////////////////////////////////////////////////
// 伤害处理
////////////////////////////////////////////////
FAR_HandleDamage_EH = { //用其他写法可能会导致单位死亡，战斗机紧急弹射失败会直接触发死亡
	params ["_unit", "_bodyPart", "_amountOfDamage", "_killer1", "_projectile", "_hitPartIndex", "_killer2"];
	
	if (local _unit && {FAR_Enable}) then {
		if (_unit getVariable ["FAR_once_eh", true]) then [{ //防止代码多次执行
			private _PartDamage = [_unit getHit "hands", _unit getHit "legs"];
			
			_amountOfDamage = if(_bodyPart in ["hands","legs"])then[{_amountOfDamage * .8},{_amountOfDamage}];
			
			if (alive _unit && {_amountOfDamage >= 1}) then { //(_unit getHit "head") > .25
				_unit setDamage 0;
				_unit allowDamage false; //多人模式有时失效!
				_amountOfDamage = 0;
				[_unit, _killer1, _killer2, _PartDamage] spawn FAR_unit_Unconscious;
			};
		},{
			if ((FAR_Invincible || {_unit getVariable ["FAR_isUnconscious",0] == 0}) && {FAR_ReviveMode != 4 || {_amountOfDamage >= 1}}) then {_amountOfDamage = 0}; //防死亡!
			
			if (FAR_shot_creep && {FAR_Invincible} && {animationState _unit == "amovppnemsprslowwrfldf_injured"} && {FAR_BleedOut > 0} && {!(_unit getVariable ["FAR_isStabilized",false])} && {_unit getVariable ["FAR_isUnconscious",0] == 1}) then {_unit setVariable ["FAR_Attacked", true]};
		}];
		_amountOfDamage
	};
};
////////////////////////////////////////////////
// 无意识相关
////////////////////////////////////////////////
FAR_actionKeys = { //禁用装备栏,架枪,望远镜,换弹夹,切换武器模式等按键 观战模式W,y键...
	if (_this select 1 in ( actionKeys "deployWeaponAuto" + actionKeys "binocular" + actionKeys "reloadMagazine" + actionKeys "nextWeapon" + actionKeys "prevWeapon" + actionKeys "watch" + actionKeys "compass" + actionKeys "gear" + (if(FAR_Talk_chat)then[{actionKeys "pushToTalk" + actionKeys "PushToTalkAll" + actionKeys "PushToTalkCommand" + actionKeys "PushToTalkDirect" + actionKeys "PushToTalkGroup" + actionKeys "PushToTalkSide" + actionKeys "PushToTalkVehicle" + actionKeys "prevChannel" + actionKeys "nextChannel" + actionKeys "chat"},{[]}]) + (if(FAR_Key_sw || {!(player getVariable ["FAR_act_menu",true])})then[{actionKeys "moveForward" + actionKeys "curatorInterface"},{[]}]) + (if(FAR_map_gps)then[{actionKeys "showMap" + actionKeys "minimap" + actionKeys "minimapToggle"},{[]}]) )) exitWith {true}; //DIK KeyCodes 按键数组
	
	if (FAR_Talk_chat && {inputAction "TacticalPing" > 0}) exitWith {true}; //组合键
	
	false
};

FAR_F_Spectator = {
	FAR_Key_sw = !FAR_Key_sw;
	if (FAR_Key_sw) then {0 spawn FAR_S_camera}; 
}; //观战模式开关

FAR_dynamicBlur = {
	"dynamicBlur" ppEffectEnable true;
	"dynamicBlur" ppEffectAdjust [6];
	"dynamicBlur" ppEffectCommit 0;
	"dynamicBlur" ppEffectAdjust [0.0];
	"dynamicBlur" ppEffectCommit 5;
}; //模糊效果

FAR_F_Text = {
	[format["<t color='#FFFFFF' size = '.5'>%1</t>", _this],-1,.863 * safeZoneH + safeZoneY,8,0,0,4623] spawn BIS_fnc_dynamicText;
}; //1.02

FAR_addKillScores = {(_this select 0) addPlayerScores [(_this select 1), 0, 0, 0, 0]};
FAR_addDeathScores = {_this addPlayerScores [0, 0, 0, 0, 1]};

FAR_UpwardMove = {
	private _anim = if(currentWeapon _this in ["","Throw"])then[{"amovppnemstpsnonwnondnon"},{"amovppnemstpsraswrfldnon"}];
	_this playMoveNow _anim;
};

FAR_addKey = {
	FAR_Key_t1 = 0;
	FAR_Key_t2 = 0;
	FAR_Key_H = 0;
	FAR_Key_sw = false;
	FAR_coerce_Spectator = true;
	if (isNil {FAR_KeyDown}) then {
	    FAR_KeyDown = (findDisplay 46) displayAddEventHandler ["KeyDown", {
	    if (player getVariable ['FAR_isUnconscious',0] == 1) then {
	        if (time > FAR_Key_t1) then {
	            if ((_this select 1) == 31) then { //S键进入观战模式
	                if (!FAR_in_Spectator && {FAR_coerce_Spectator}) then [{call FAR_F_Spectator},{"锁定在观战模式无法关闭" call FAR_F_Text}];
	            };
				if ((_this select 1) == 33 && {!isNull (player getVariable ["FAR_call_AI", objNull])} && {player getVariable ["FAR_act_menu",true]}) then { //F键切换AI医护兵接敌模式
					_ai = player getVariable ["FAR_call_AI", objNull];
					if (primaryWeapon _ai == "" && {handGunWeapon _ai == ""} && {secondaryWeapon _ai == ""} && {isNull objectParent _ai}) exitWith {};
					private ["_ATAG","_str"];
	                _ATAG = if(player getVariable ["FAR_DISABLE_ATAG", false])then[{_str = "允许"; false},{_str = "禁止"; true}];
					player setVariable ["FAR_DISABLE_ATAG", _ATAG, true];
					systemchat format["AI医护兵%1与敌人交战", _str];
	            };
	            if ((_this select 1) == 45 && {!isNull (player getVariable ["FAR_call_AI", objNull])} && {player getVariable ["FAR_act_menu",true]}) then { //X键取消AI救治
					player setVariable ["FAR_CallAI_X", true, true];
				};
				FAR_Key_t1 = time + .5;
	        };
			if (time > FAR_Key_t2) then {
	            if ((_this select 1) == 34 && {!isNull (player getVariable ["FAR_call_AI", objNull])} && {player getVariable ["FAR_act_menu",true]}) then { //G键呼叫AI丢烟
					player setVariable ["FAR_CallAI_Smoke", true, true];
					systemchat "呼叫AI医护兵丢烟";
				};
				FAR_Key_t2 = time + 3;
	        };
	        if (time > FAR_Key_H && {_this select 1 == 35} && {alive player}) then { //H键呼救
				_chat = selectRandom ["Help!", "救命!", "995", "我倒下了！我倒下了！", "救我...", "我倒了", "我被暴菊了，救我！", "救一下我", "jiu jiu wo", "Help me!", "我倒了，需要你的帮助", "medic!", "菊花残，满腚伤，救我...", "is down!", "谁来救救我", "附近老铁救一下我", "重伤，倒下", "倒地，已经失去意识！", "有队友倒下，需要帮助！", "我中弹了！医护兵！", "我躺了！医疗兵！", "我需要医疗兵！", "救命，我中枪了！", "倒下，这里有谁能帮助吗", "我又躺了，帮帮我", "我躺了！谁过来拉我一把", "倒下，附近队友拉下我", "帮帮我，我倒下了", "医护兵！", "靠，我又倒了", "医疗兵快来，我还不想死！", "我被击中了!", "需要医疗护理!", "一救二，二救四，四救全队", "啊~~我倒了！"];
				_side = player getVariable ["FAR_unit_Side", side player];
				FAR_remote_EH = [player, _side, "help_chat", [_chat, FAR_near_medic]];
				publicVariable "FAR_remote_EH";
				//if("ItemRadio" in assignedItems player)then[{player groupChat _chat},{systemChat format["%1: %2", name player,_chat]}];
				player globalChat _chat;
				if (FAR_callAI_en && {player getVariable ["FAR_act_menu",true]} && {call FAR_callAI_condition}) then {[player,_side] spawn FAR_callFriendlies_AI};
				FAR_Key_H = time + 8;
		    };
			_this call FAR_actionKeys;
		};}];
		FAR_MMH = (findDisplay 46) displayAddEventHandler ["MouseMoving", {
			if (player getVariable ['FAR_isUnconscious',0] == 1 && {!(player getVariable ['FAR_isDragged',false])} && {!(player getVariable ['FAR_isCarry',false])} && {animationState player != 'amovppnemsprslowwrfldf_injured'} && {vehicle player == player}) then {player setDir FAR_dir_save};
		}]; //禁止移动鼠标改变方向
	};
};

FAR_unit_Unconscious = { //无意识处理
params ["_unit", "_killer1", "_killer2", "_PartDamage"];

if (_unit getVariable ["FAR_once_eh", true]) then {

	_unit setVariable ["FAR_once_eh", false, true];
	_side = side _unit; //
	_unit setVariable ["FAR_unit_Side", _side, true];
	_unit setVariable ["FAR_DISABLE_ATAG", nil];
	
	//倒下和击伤提示，计分板，友军击伤惩罚
	_killer = objNull; //击杀者不太准确
	if ((_killer1 == _killer2 || {isNull _killer2}) && {_killer1 isKindOf "CaManBase"}) then {_killer = _killer1}; //步兵&车撞&手雷
	if (_killer1 != _killer2 && {_killer2 isKindOf "CaManBase"}) then {_killer = _killer2}; //载具炮手
	FAR_deathMessage2 = [_unit, _killer, _side];
	publicVariable "FAR_deathMessage2";
	["FAR_deathMessage2", FAR_deathMessage2] call FAR_public_EH;
	
	if (_unit == player) then {
		_uav = getConnectedUAV _unit;
		_uavControl = (UAVControl _uav) select 1; //返回UAV操控位置
		//if (_uavControl != "") then {_unit connectTerminalToUAV objNull}; //断开UAV
		if (_uavControl != "") then {_unit action ["SwitchToUAVDriver", _uav]; _uav action ["BackFromUAV", _unit]}; //放弃操控UAV
		if (!FAR_death_Effect || {vehicle _unit != _unit}) then {
			FAR_BLACK_FADED = 1;
			TitleText ["", "BLACK FADED"];
		};
		closedialog 0;
		enableRadio false;
		if (isMultiplayer) then {
			{inGameUISetEventHandler _x} forEach [["PrevAction", "true"],["NextAction", "true"],["Action", "true"]]; //不隐藏话受伤后玩家能用游戏的“自我医疗”会导致滚轮选项不显示的严重bug！
			if(FAR_death_Score)then{player remoteExec ["FAR_addDeathScores", 2]}; //计分板死亡分数+1 *AI?
			FAR_isDownMove = false; //
		};
		private _num = _unit getVariable ["FAR_count_down", 0];
		_unit setVariable ["FAR_count_down", _num + 1, true];
	};
	
	_unit stop true;
	{_unit disableAI _x} forEach ["MOVE","TARGET","AUTOTARGET","ANIM","CHECKVISIBLE"];
	
    _unit allowDamage false;
	
	// 单位弹出载具
	while {vehicle _unit != _unit && {!alive (vehicle _unit) || {vehicle _unit isKindOf "StaticWeapon"} || {vehicle _unit isKindOf "Motorcycle"}} && {alive _unit}} do {
		//_u leaveVehicle _v;
		//[_u] allowGetIn false; //
		unAssignVehicle _unit;
		_unit action ["eject", vehicle _unit]; //"紧急逃生"
		sleep .5;//2
		//完成跨出摩托动作
		if (animationState _unit in ["getoutquadbike_cargo","getoutquadbike"]) then {sleep 1.6};
		if (_unit == vehicle _unit) exitWith {};
		_unit action ["getout", vehicle _unit]; //"离开"
		sleep .5;
		if (_unit == vehicle _unit) exitWith {};
		_unit setPos (_unit modelToWorld [0,0,0]);
	}; //moveOut _this; //bug下车站立定住
	
	_unit setDamage 0; //0.5
    _unit setVelocity [0,0,0];
	_unit setCaptive true;
	
	if (!isNil "FAR_revive_move" || {animationState _unit in ["ainvpknlmstpslaywrfldnon_medic","ainvpknlmstpslaywpstdnon_medic","ainvpknlmstpslaywnondnon_medic","ainvppnemstpslaywrfldnon_medicother","AinvPknlMstpSnonWnonDnon_medic0S","AinvPknlMstpSnonWnonDnon_medic0","AinvPknlMstpSnonWnonDnon_medic1","AinvPknlMstpSnonWnonDnon_medic2","AinvPknlMstpSnonWnonDnon_medic3","AinvPknlMstpSnonWnonDnon_medicEnd"]}) then [{
	    [_unit, "switchMove", "AinjPpneMstpSnonWrflDnon"] call FAR_remote_move;
	},{
		if (!FAR_death_Effect || {vehicle _unit != _unit} || {FAR_isCarry}) then {[_unit, "ainjppnemstpsnonwrfldnon_rolltoback"] remoteExec ["playMoveNow", 0]};
	}]; //"AinjPpneMstpSnonWrflDnon_injuredHealed"
	
	_index = _unit addEventHandler ["fired", {deleteVehicle (_this select 6)}]; //开火无效
	
	if (FAR_death_Effect && {_unit == vehicle _unit} && {!FAR_isCarry}) then {_unit setUnconscious true};
	
	[_unit, _killer, _side] spawn FAR_un_script;
	
	sleep 3;
    
	if (_unit == player) then {
		openMap [false,false];
		if(!isNil "FAR_BLACK_FADED")then{FAR_BLACK_FADED = nil; TitleText ["", "BLACK IN", 1]};
		call FAR_dynamicBlur;
		closedialog 0;
		enableRadio true;
		if(FAR_MuteACRE)then{_unit setVariable ["ace_sys_wounds_uncon", true]}; //静音ACRE无线电模拟
		call FAR_addKey; //添加按键EH
		if(FAR_in_Spectator)then{call FAR_F_Spectator}; //是否强制进入观战模式
	};
	
	if (FAR_ReviveMode == 4) then {
		_PartDamage params ["_hands", "_legs"];
		_unit setDamage ((random .32)+.2);
		_unit allowDamage true; //
		if (_hands > .28) then {_unit setHit ["hands", .5]};
		if (_legs > .28) then {_unit setHit ["legs", .5]}; //腿瘸了按W键无法使用倒下配套的爬行动作
		_unit allowDamage false; //先执行导致setHit失效
	};
	
	if (!isNil "AR_Rappel_Detach_Action" && {[_unit] call AR_Rappel_Detach_Action_Check}) then {
		[_unit] call AR_Rappel_Detach_Action; //分离直升机索降装置
	};
	if (!isNil "AUR_Rappel_Detach_Action" && {[_unit] call AUR_Rappel_Detach_Action_Check}) then {
		[_unit] call AUR_Rappel_Detach_Action; //分离建筑物索降装置
	};
	
	if (_unit == vehicle _unit) then [{
		[_unit, "switchMove", "AinjPpneMstpSnonWrflDnon"] call FAR_remote_move; //*能让攀爬梯子的单位掉落
		if (FAR_death_Effect && {!FAR_isCarry}) then {_unit setUnconscious false}; //
		
		if ((getPos _unit select 2) > 2) then {
		    waitUntil {if(!alive _unit)exitwith{true};_unit setVelocity [0,0,-9999];sleep .1;((velocity _unit) select 2)<8 && {(getPos _unit select 2)<2}};
		    _unit setVelocity [0,0,0];
		};
	},{
		_veh = vehicle _unit;
		_unit action ["SuspendVehicleControl", _veh]; //*如果是副驾则"放弃驾驶"
		if (_veh isKindOf "air" && {_unit == driver _veh}) then {
			_copilot = objNull; //副驾驶或者可接手驾驶的炮手
			{if (toLower(_x select 1) in ["turret","gunner","commander"] && {_x select 3 isEqualTo [0]} && {_x select 2 == -1}) exitWith {_copilot = _x select 0}} forEach fullCrew _veh;
			if (alive _copilot && {_copilot in (call BIS_fnc_listPlayers)} && {_copilot getVariable ["FAR_isUnconscious",0] == 0}) then {_copilot action ["TakeVehicleControl", _veh]; _str = "驾驶员倒下! 接手驾驶!"; [[_str, "Plain Down"]] remoteExec ["TitleText", _copilot]; _str remoteExec ["FAR_Radio_hint1", _copilot]};
		}; //_role = assignedVehicleRole _this; //不可靠，必须本地判断在载具里
	}];
	
	_unit setVariable ["FAR_AI_RS_t", time + (5 + random 25)];
	_unit setVariable ["FAR_isUnconscious", 1, true];
	
	if (!FAR_Invincible) then {_unit allowDamage true}; //
	
	_makeName = Format ["FAR_%1_%2", _unit,time/60];
	["FAR_Damage_make", [_unit,_makeName]] call FAR_public_EH;

	if (isMultiplayer) then {
		FAR_Damage_make = [_unit,_makeName];
		publicVariable "FAR_Damage_make";
		
		if(FAR_playableUnit)then {_unit setVariable ["FAR_before_group", group _unit, true]}; ////
	};
  	/////////////////////////////////////////////////
	_bleedOut = 0;
	[_unit, _side] call FAR_hint1;
	_unit setVariable ["FAR_unitbleedOut", "", true];
	if (_unit == player) then [{
		if (_unit getVariable ["FAR_isStabilized",false]) then {
			_unit setVariable ["ace_sys_wounds_uncon", false];
			[_unit, _side] call FAR_hint2;
		};
		if (FAR_BleedOut > 0 && {time > _bleedOut} && {_unit getVariable ["FAR_isUnconscious",0] == 1} && {!(_unit getVariable ["FAR_isStabilized",false])}) then {
			_unit setCaptive false; //
			if(_unit == vehicle _unit)then{_unit switchMove "deadstate"};
			_unit setDamage 1;
			if(_unit == player && {!isNil 'xxx_CamShake'})then{resetCamShake; xxx_CamShake = nil};
		};
		if (isMultiplayer) then {
			{inGameUISetEventHandler _x} forEach [["PrevAction", "false"],["NextAction", "false"],["Action", "false"]];
		}; //滚轮菜单可用
		//enableRadio true;
		//_unit enableSimulation true;//
		if (FAR_Key_sw) then {FAR_Key_sw = false}; //退出观战模式
		if (!isNil {FAR_KeyDown}) then {
			(findDisplay 46) displayRemoveEventHandler ["KeyDown", FAR_KeyDown];
			(findDisplay 46) displayRemoveEventHandler ["MouseMoving", FAR_MMH];
			FAR_KeyDown = nil;
		};
		if (_unit == player) then {
			_unit setVariable ["ace_sys_wounds_uncon", false];
			sleep .5;
			if(cameraView == "INTERNAL")then{player switchCamera "External"}; //
			hintSilent "";
			if(!isNil 'xxx_CamShake')then{resetCamShake; xxx_CamShake = nil};
		};
		if (alive _unit) then {
			_unit stop false;
			{_unit enableAI _x} forEach ["MOVE","TARGET","AUTOTARGET","ANIM","CHECKVISIBLE"];
			if (FAR_ReviveMode != 4) then {_unit setDamage 0};
			_unit allowDamage true;
			_unit setCaptive false;
			if (_unit == vehicle _unit) then {_unit call FAR_UpwardMove};
		};
		(if(isMultiplayer)then[{player},{_unit}]) removeEventHandler ["fired", _index]; //开火有效
		
	},{ ///////////AI//////////////
		if (_unit getVariable ["FAR_isStabilized",false]) then {[_unit, _side] call FAR_hint2};
		if (FAR_BleedOut > 0 && {time > _bleedOut} && {_unit getVariable ["FAR_isUnconscious",0] == 1} && {!(_unit getVariable ["FAR_isStabilized",false])}) then {
			_unit setCaptive false;
			if(_unit == vehicle _unit)then{_unit switchMove "deadstate"};
			_unit setDamage 1;
			_unit setVariable ["FAR_isUnconscious", 0, true]; //
			if(_unit == player && {!isNil 'xxx_CamShake'})then{resetCamShake; xxx_CamShake = nil};
		};
		_unit removeEventHandler ["fired", _index];
		_unit setVariable ["FAR_unit_Side", nil, true]; //
		if(_unit == player)then{hintSilent ""; if(!isNil 'xxx_CamShake')then{resetCamShake; xxx_CamShake = nil}};
	}];
	
	if (FAR_death_Effect) then {_unit setUnconscious false}; //
};};
////////////////////////////////////////////////
//文本提示
////////////////////////////////////////////////
FAR_hint1 = {
	params ["_unit", "_side"];
	_tt1 = 0;
	_tt2 = 0;
	_bleedOut = time + FAR_BleedOut;
	_unit setVariable ["FAR_Attacked", nil];
	while { !isNull _unit && {alive _unit} && {_unit getVariable ["FAR_isUnconscious",0] == 1} && {!(_unit getVariable ["FAR_isStabilized",false])} && {FAR_BleedOut <= 0 || {time < _bleedOut}} } do {
		_unitbleedOut = round (_bleedOut - time);
		if (_unit == player) then {
			_bleedtext = if(FAR_BleedOut <= 0)then [{"已经过去了"},{"正在流血"}];
			_e = if(FAR_Key_sw)then[{"<br/>"},{"\n"}];
			_r = (_unit getVariable ["FAR_reviveTime", [0,0]]) select 1;
			_s = (_unit getVariable ["FAR_StabilizeTime", [0,0]]) select 1;
			_str1 = if(_r > 0)then[{format["%2救治进度 r:%1％", _r,_e]},{""}];
			_str2 = if(_s > 0)then[{format["%2止血进度 s:%1％", _s,_e]},{""}];
		    if (FAR_Key_sw) then [{
				[format["<t color='#ffffff' size = '.4'>%1 %2秒%3%4<br/>%5</t>", _bleedtext, abs _unitbleedOut, _str1, _str2, _side call FAR_CheckFriendlies],-.396 + safeZoneX,.907 * safeZoneH + safeZoneY,3,0,0,171] spawn BIS_fnc_dynamicText; //16:9 -.848 1.081
			},{
			    hintSilent format["%1 %2秒%3%4\n%5", _bleedtext, abs _unitbleedOut, _str1, _str2, _side call FAR_CheckFriendlies];
			}];
			if (time > _tt1 && {!FAR_Key_sw}) then {
				_tt1 = time + 3;
				[ 10000 ] call BIS_fnc_bloodEffect;
				if (animationState _unit == "amovppnemsprslowwrfldf_injured") then [{
					enableCamShake true;
					addCamShake [15, 10, 0.7];
					xxx_CamShake = 1;
				    if (FAR_BleedOut > 0) then [{
						_rt = round random 20;
						_str = if(FAR_shot_creep && {FAR_Invincible} && {_unit getVariable ["FAR_Attacked",false]})then[{_rt = _rt + (FAR_bleed_creep2 call BIS_fnc_randomInt); _unit setVariable ["FAR_Attacked", nil]; "受到攻击"},{"爬动"}];
						TitleText [Format["%1会加速失血！ (-%2s)", _str, _rt], "BLACK", 1];
						titleFadeOut 2;
						_bleedOut = _bleedOut - _rt;
					},{
						TitleText ["","BLACK",1];
						titleFadeOut 2;
					}];
					if (FAR_shot_creep && {!FAR_Invincible || {FAR_BleedOut > 0}}) then {_unit setCaptive false}; //
				},{if(!isNil "xxx_CamShake")then{resetCamShake; xxx_CamShake = nil; _unit setCaptive true; _unit setVariable ["FAR_Attacked", nil];}}];
			};
			if (FAR_Key_sw && {!isNil "xxx_CamShake"}) then {resetCamShake; xxx_CamShake = nil; _unit setCaptive true; _unit setVariable ["FAR_Attacked", nil];};
			if (time > _tt2) then {
				_tt2 = time + 13;
				_str = if(FAR_allow_suicide)then[{format[localize "STR_far_hint1",actionKeysImages "action"]},{""}];
				[Format[localize "STR_far_hint2",_str],-1,.01 * safeZoneH + safeZoneY,10,1,0,169] spawn BIS_fnc_dynamicText;
			};
		};
		if(FAR_bleedTime)then {_unit setVariable ["FAR_unitbleedOut", format["%1s ", _unitbleedOut], true]};
		sleep 1;
	};
};

FAR_hint2 = {
	params ["_unit", "_side"];
	_tt1 = 0;
	_tt2 = 0;
	while { !isNull _unit && {alive _unit} && {_unit getVariable ["FAR_isUnconscious",0] == 1} } do {
		if (_unit == player) then {
			_r = (_unit getVariable ["FAR_reviveTime", [0,0]]) select 1;
			_str = if(_r > 0)then[{format["%2救治进度 r:%1％", _r, if(FAR_Key_sw)then[{"<br/>"},{"\n"}]]},{""}];
			if (FAR_Key_sw) then [{
				[format["<t color='#ffffff' size = '.4'>已经止血%1<br/>%2</t>", _str, _side call FAR_CheckFriendlies],-.396 + safeZoneX,.907 * safeZoneH + safeZoneY,3,0,0,171] spawn BIS_fnc_dynamicText;
			},{
			    hintSilent format["已经止血%1\n%2", _str, _side call FAR_CheckFriendlies];
			}];
			if (FAR_shot_creep && {!FAR_Invincible} && {time > _tt1}) then {
				_tt1 = time + 3;
				if (animationState _unit == "amovppnemsprslowwrfldf_injured") then [{
					xxx_CamShake = 1;
					_unit setCaptive false;
				},{if(!isNil "xxx_CamShake")then{xxx_CamShake = nil; _unit setCaptive true}}];
			}; //
			if (time > _tt2) then {
				_tt2 = time + 13;
				_str = if(FAR_allow_suicide)then[{format[localize "STR_far_hint1",actionKeysImages "action"]},{""}];
				[Format[localize "STR_far_hint2",_str],-1,.01 * safeZoneH + safeZoneY,10,1,0,169] spawn BIS_fnc_dynamicText;
			};
		};
		sleep .5;
	};
};

////////////////////////////////////////////////
//玩家医治目标单位
////////////////////////////////////////////////
FAR_medic_anim = {
	private ["_a","_b","_c"];
	_curWep = currentWeapon _this; //空手不一定为是""可能是"Throw"
	if (stance _this == "PRONE") then [{
		switch true do {
			case (_curWep == primaryWeapon _this && {primaryWeapon _this != ""}): {
				_a = "amovppnemstpsraswrfldnon";
				_b = "ainvppnemstpslaywrfldnon_medicother";
				_c = 8.6;
			};
			case (_curWep == handGunWeapon _this && {handGunWeapon _this != ""}): {
				_a = "amovppnemstpsraswpstdnon";
				_b = "ainvppnemstpslaywpstdnon_medicother";
				_c = 8;
			};
			case (_curWep in ["","Throw"]): {
				_a = "amovppnemstpsnonwnondnon";
				_b = "ainvppnemstpslaywnondnon_medicother";
				_c = 8;
			};
			default {
				_a = "amovppnemstpsraswrfldnon";
				_b = "ainvppnemstpslaywrfldnon_medicother";
				_c = 8.6;
				_this switchMove _a;
			};
		};
	},{
		switch true do {
			case (_curWep == primaryWeapon _this && {primaryWeapon _this != ""}): {
				_a = "AmovPknlMstpSrasWrflDnon";
				_b = "ainvpknlmstpslaywrfldnon_medic";
				_c = 6.7;
			};
			case (_curWep == handGunWeapon _this && {handGunWeapon _this != ""}): {
				_a = "amovpknlmstpsraswpstdnon";
				_b = "ainvpknlmstpslaywpstdnon_medic"; //"ainvpknlmstpslaywpstdnon_medicin"
				_c = 8.2;
			};
			case (_curWep == secondaryWeapon _this && {secondaryWeapon _this != ""}): {
				_a = "amovpknlmstpsraswlnrdnon"; //
				_b = "ainvpknlmstpslaywnondnon_medic"; //
				_c = 10.2;
			};
			case (_curWep in ["","Throw"]): {
				_a = "amovpknlmstpsnonwnondnon";
				_b = "ainvpknlmstpslaywnondnon_medic"; //"ainvpknlmstpslaywnondnon_medicin"
				_c = 7.5;
			};
			default {
				_a = "AmovPknlMstpSrasWrflDnon";
				_b = "ainvpknlmstpslaywrfldnon_medic";
				_c = 6.7;
			};
		};
	}];
	[_a,_b,_c]
};
FAR_Revive_Check1 = {
	(_unit getVariable ["FAR_isUnconscious",0] == 0 || {_unit getVariable ["FAR_isDragged",false]} || {_unit getVariable ["FAR_isCarry",false]} || {vehicle _unit != _unit} || {!alive _unit} || {!alive _medic} || {lifeState _medic == "INCAPACITATED"} || {_medic getVariable ["FAR_isUnconscious",0] == 1} || {_medic distance _unit > 2} || {FAR_ReviveMode == 2 && {!("Medikit" in items _medic || {"Medikit" in items _unit})}} || {FAR_ReviveMode == 3 && {!("FirstAidKit" in items _medic || {"FirstAidKit" in items _unit} || {"Medikit" in items _medic} || {"Medikit" in items _unit})}})
};
FAR_Revive_code = {
	_str = format["%1 正在救治 %2", _medicName, _unitName];
	_str remoteExec ["systemChat", _side_t];
	if(side player != _side_t)then{_str remoteExec ["systemChat", side player]};
	TitleText ["按X键取消医治", "Plain Down"];
	_X_Key = (findDisplay 46) displayAddEventHandler ["KeyDown", {if((_this select 1) == 45)then {FAR_CancelRevive = true}}];
};
FAR_Revive_code1 = {
	
	_unit call FAR_var_init;
	
	if (FAR_ReviveMode == 3 && {!("Medikit" in items _medic || {"Medikit" in items _unit})}) then {
		[_unit, _medic] call FAR_fn_removeFAK;
	}; //模式3没有医疗包删除一个急救包
	
	if (FAR_ReviveMode == 4) then {
		private _check = ("Medikit" in items _medic || {"Medikit" in items _unit} || {damage _unit < .35 && {_unit getHit "hands" < .35} && {_unit getHit "legs" < .35}});
		if (!isNil "FAR_ReviveMode4_sw" || {_check}) then {
			if (_check) then [{
				_unit setDamage 0; 
			},{
				if (damage _unit >= .35 || {_unit getHit "hands" >= .35} || {_unit getHit "legs" >= .35}) then {
					_unit setDamage 0; 
					[_unit, _medic] call FAR_fn_removeFAK;
				};
			}];
		};
	}; //模式4
	
	[_unit, _medic] spawn FAR_revive_script;
	
	if (!isPlayer _unit) then { //{!(_unit in (call BIS_fnc_listPlayers)}
		[nil, [_unit, nil, "ReviveAI", nil]] call FAR_remote_exec;
		if (isMultiplayer) then {
		    FAR_remote_EH = [_unit, nil, "ReviveAI", nil];
		    publicVariable "FAR_remote_EH";
		};
	}; //AI
};
FAR_Revive_code2 = {
	if (!_isDownMove || {FAR_isDownMove}) then {inGameUISetEventHandler ["Action", "false"]};
	(findDisplay 46) displayRemoveEventHandler ["MouseMoving", _MMH2];
	(findDisplay 46) displayRemoveEventHandler ["KeyDown", _X_Key];
	FAR_revive_move = nil;
	FAR_ReviveMode4_sw = nil;
};
FAR_medic_anim2 = ["AinvPknlMstpSnonWnonDnon_medic0","AinvPknlMstpSnonWnonDnon_medic1","AinvPknlMstpSnonWnonDnon_medic2","AinvPknlMstpSnonWnonDnon_medic3"];
FAR_anima_loop = {
	waitUntil {
		if (_this getVariable ["FAR_anima_loop", true] || {_this getVariable ["FAR_isUnconscious",0] == 1} || {!alive _this}) exitWith {true};
		if !(animationState _this in FAR_medic_anim2) then {_this playMove (selectRandom FAR_medic_anim2)};
		sleep .5;
		false
	};
	_this setVariable ["FAR_anima_loop", nil];
};
FAR_Revive2_code1 = {
	_Rp = 0;
	_Progress = if(FAR_actMode == 1)then[{(_unit getVariable ["FAR_reviveTime", [0,0]]) select 0},{0}];
	_medic setVariable ["FAR_anima_loop", false];
	//_medic playMoveNow "AinvPknlMstpSnonWnonDnon_medic0S";
	_medic spawn FAR_anima_loop;
	sleep 3;
	_startTime = time - _Progress;
	_reviveTime = time + (FAR_reviveTime - _Progress);
	waitUntil {
		if (FAR_actMode == 1) then {
			_Progress = time - _startTime;
			_Rp = if(player == _medic)then[{[_Progress,FAR_reviveTime,.6,"#008000",.149] call k1_fn_ProgressBar},{[_Progress,FAR_reviveTime] call FAR_rs_progress}];
			_unit setVariable ["FAR_reviveTime", [_Progress,_Rp], true];
		};
		_check = (call FAR_Revive_Check1 || {if(player == _medic)then[{FAR_CancelRevive},{[_medic,_unit] call FAR_callAI_checkCond}]});
		if (_check || {time > _reviveTime} || {_Rp >= 100}) exitWith {true};
		sleep .5;
		false
	};
	if(!isNil{_medic getVariable ["FAR_anima_loop",nil]})then{_medic setVariable ["FAR_anima_loop",true]};
	waitUntil {!(_medic getVariable ["FAR_anima_loop", false])};
	//_medic playMoveNow "AinvPknlMstpSnonWnonDnon_medicEnd";
	if(alive _medic && {_medic getVariable ["FAR_once_eh", true]})then{_medic playActionNow "medicStop"; sleep 3;};
	_isDownMove = (animationState _medic == "ainjppnemstpsnonwrfldnon");
};

FAR_HandleRevive = {
	if (alive _this && {_this isKindOf "CaManBase"}) then {
		(player call FAR_medic_anim) params ["_a","_b","_c"];
		private ["_side_t","_check","_MMH2","_X_Key","_medicName","_unitName"];
		_medicName = name player;
		_unitName = name _this;
		FAR_revive_move = 1;
		FAR_CancelRevive = false;
		FAR_isDownMove = true; //
		_time_revive1 = time + 5; //切换到蹲姿的预留时间 *1.5
		FAR_remote_EH = [_this, player, "actDisable_debug", _a];
		_side_t = _this getVariable ["FAR_unit_Side", side _this];
		player playMoveNow _b;
		_this setVariable ["FAR_act_menu", false, true]; //隐藏其他玩家FAR菜单
		publicVariable "FAR_remote_EH";
		inGameUISetEventHandler ["Action", "true"]; //玩家禁用滚轮菜单
		FAR_dir_save = getDir player;
		_MMH2 = (findDisplay 46) displayAddEventHandler ["MouseMoving", {if(!isNil "FAR_revive_move")then{player setDir FAR_dir_save}}];
		waitUntil {animationState player in [_b,"ainjppnemstpsnonwrfldnon"] || {time > _time_revive1}};
		call FAR_Revive_code;
		_medic = player;
		_unit = _this;
		_time_Minimum = time; //
		_time_revive2 = time + _c; //6.3 sec time-out
        waitUntil {_check = (call FAR_Revive_Check1 || {FAR_CancelRevive}); (_check || {animationState player != _b} || {time > _time_revive2})};
		_isDownMove = (animationState player == "ainjppnemstpsnonwrfldnon");
		_isDownMove2 = (animationState player == "unconscious");
		if (_isDownMove || {_check} || {_isDownMove2} || {time - _time_Minimum < 5} || {vehicle player != player}) then [{
			if (FAR_isDownMove && {!_isDownMove2} && {vehicle player == player} && {lifeState player != "INCAPACITATED"})then {[player, "switchMove", _a] call FAR_remote_move}; //
			_this setVariable ["FAR_act_menu", true, true];
			_str = format["%1 没有救起 %2", _medicName, _unitName];
			_str remoteExec ["systemChat", _side_t];
			if(side player != _side_t)then{_str remoteExec ["systemChat", side player]};
		},{
			private _num = player getVariable ["FAR_count_revive", 0];
			player setVariable ["FAR_count_revive", _num + 1, true];
			call FAR_Revive_code1;
		}];
		call FAR_Revive_code2;
		//水下或空手救人卡动作除错
		if (animationState player == _b || {time > _time_revive2}) then {player switchMove _a};
	};
};

FAR_HandleRevive2 = {
	if (alive _this && {_this isKindOf "CaManBase"}) then {
		private ["_side_t","_check","_isDownMove","_Rp","_MMH2","_X_Key","_medicName","_unitName"];
		_medicName = name player;
		_unitName = name _this;
		FAR_revive_move = 1;
		FAR_CancelRevive = false;
		FAR_isDownMove = true;
		FAR_remote_EH = [_this, player, "actDisable_debug", "AinvPknlMstpSnonWnonDnon_medicEnd"]; //
		_side_t = _this getVariable ["FAR_unit_Side", side _this];
		_this setVariable ["FAR_act_menu", false, true];
		publicVariable "FAR_remote_EH";
		inGameUISetEventHandler ["Action", "true"];
		FAR_dir_save = getDir player;
		_MMH2 = (findDisplay 46) displayAddEventHandler ["MouseMoving", {if(!isNil "FAR_revive_move")then{player setDir FAR_dir_save}}];
		call FAR_Revive_code;
		_medic = player;
		_unit = _this;
		call FAR_Revive2_code1;
		if (_Rp < 100 && {_isDownMove || {_check} || {animationState player == "unconscious"} || {vehicle player != player}}) then [{
			_this setVariable ["FAR_act_menu", true, true];
			_str = format["%1 没有救起 %2", _medicName, _unitName];
			_str remoteExec ["systemChat", _side_t];
			if(side player != _side_t)then{_str remoteExec ["systemChat", side player]};
		},{
			private _num = player getVariable ["FAR_count_revive", 0];
			player setVariable ["FAR_count_revive", _num + 1, true];
			call FAR_Revive_code1;
		}];
		call FAR_Revive_code2;
	};
};

FAR_HandleRevive3 = {
	if (alive _this && {_this isKindOf "CaManBase"} && {_this getVariable ["FAR_isUnconscious",0] == 1} && {player distance _this < 2}) then {
		private _num = player getVariable ["FAR_count_revive", 0];
		player setVariable ["FAR_count_revive", _num + 1, true];
		_medic = player;
		_unit = _this;
		call FAR_Revive_code1;
	};
};

////////////////////////////////////////////////
// 止血
////////////////////////////////////////////////
FAR_Stabilize_Check1 = {
	(_unit getVariable ["FAR_isUnconscious",0] == 0 || {_unit getVariable ["FAR_isStabilized",false]} || {_unit getVariable ["FAR_isDragged",false]} || {_unit getVariable ["FAR_isCarry",false]} || {vehicle _unit != _unit} || {!alive _unit} || {!alive _medic} || {lifeState _medic == "INCAPACITATED"} || {_medic getVariable ["FAR_isUnconscious",0] == 1} || {_medic distance _unit > 2} || {FAR_ReviveMode == 2 && {!("FirstAidKit" in items _medic || {"FirstAidKit" in items _unit})}})
};
FAR_Stabilize_code = {
	_str = format["%1 正在给 %2 止血.", _medicName, _unitName];
	_str remoteExec ["systemChat", _side_t];
	if(side player != _side_t)then{_str remoteExec ["systemChat", side player]};
	TitleText ["按X键取消止血", "Plain Down"];
	_X_Key = (findDisplay 46) displayAddEventHandler ["KeyDown", {if((_this select 1) == 45)then {FAR_CancelRevive = true}}];
};
FAR_Stabilize_code1 = {
	if ((!_check || {FAR_actMode == 1 && {_Sp >= 100}}) && {FAR_actMode != 0 || {_t2 - time < 2.5}}) then [{
		_unit setVariable ["FAR_isStabilized", true, true];
		_unit setVariable ["FAR_StabilizeTime", [0,0], true];
		if (!isPlayer _medic && {FAR_join_side} && {(random 100) < 50}) then {[_medic, _side_t, 40] spawn FAR_fn_joinGro};
		if (FAR_ReviveMode in [0,2] && {!("Medikit" in items _medic || {"Medikit" in items _unit})}) then {
			[_unit, _medic] call FAR_fn_removeFAK;
		};
		if (FAR_actMode == 0 && {animationState _medic == _b}) then {_medic switchMove _a};
	},{
		if (FAR_actMode == 0) then {_medic switchMove _a};
		_aiStr = if(isPlayer _medic)then[{""},{"(AI)"}];
		_str = format["%1%3 未能给 %2 止血.", _medicName, _unitName, _aiStr];
		_str remoteExec ["systemChat", _side_t];
		if(isPlayer _medic && {side _medic != _side_t})then{_str remoteExec ["systemChat", side _medic]};
	}];
	_unit setVariable ["FAR_act_menu", true, true];
	if (isPlayer _medic) then {
		if (!(animationState _medic in ["ainjppnemstpsnonwrfldnon_rolltoback","ainjppnemstpsnonwrfldnon","ainjppnemstpsnonwrfldnon_rolltofront"]) && {_medic getVariable ["FAR_once_eh", true]}) then {
		    inGameUISetEventHandler ["Action", "false"];
		};
		(findDisplay 46) displayRemoveEventHandler ["KeyDown", _X_Key];
		(findDisplay 46) displayRemoveEventHandler ["MouseMoving", _MMH2];
		FAR_revive_move = nil;
	};
	_medic setUnitPos "AUTO";
};
FAR_Stabilize2_code1 = {
	_Sp = 0;
	_Progress = if(FAR_actMode == 1)then[{(_unit getVariable ["FAR_StabilizeTime", [0,0]]) select 0},{0}];
	_medic setVariable ["FAR_anima_loop", false];
	//_medic playMoveNow "AinvPknlMstpSnonWnonDnon_medic0S";
	_medic spawn FAR_anima_loop;
	sleep 3;
	_startTime = time - _Progress;
	_StabilizeTime = time + (FAR_StabilizeTime - _Progress);
	waitUntil {
		if (FAR_actMode == 1) then {
			_Progress = time - _startTime;
			_Sp = if(player == _medic)then[{[_Progress,FAR_StabilizeTime,.6,"#008000",.149] call k1_fn_ProgressBar},{[_Progress,FAR_StabilizeTime] call FAR_rs_progress}];
			_unit setVariable ["FAR_StabilizeTime", [_Progress,_Sp], true];
		};
		_check = (call FAR_Stabilize_Check1 || {if(player == _medic)then[{FAR_CancelRevive},{false}]});
		if (_check || {time > _StabilizeTime} || {_Sp >= 100}) exitWith {true};
		sleep .5;
		false
	};
	if(!isNil{_medic getVariable ["FAR_anima_loop",nil]})then{_medic setVariable ["FAR_anima_loop",true]};
	waitUntil {!(_medic getVariable ["FAR_anima_loop", false])};
	//_medic playMoveNow "AinvPknlMstpSnonWnonDnon_medicEnd";
	if(alive _medic && {_medic getVariable ["FAR_once_eh", true]})then{_medic playActionNow "medicStop"; sleep 3;};
};

FAR_HandleStabilize = {
	if (alive _this && {_this isKindOf "CaManBase"}) then {
		(player call FAR_medic_anim) params ["_a","_b","_c"];
		private ["_medic","_unit","_t1","_t2","_side_t","_check","_MMH2","_X_Key","_medicName","_unitName"];
		_medicName = name player;
		_unitName = name _this;
		_t1 = time + 5;
		FAR_revive_move = 1;
		FAR_CancelRevive = false;
		FAR_remote_EH = [_this, player, "actDisable_debug", _a];
		player playMoveNow _b;
		_this setVariable ["FAR_act_menu", false, true];
		publicVariable "FAR_remote_EH";
		inGameUISetEventHandler ["Action", "true"];
		FAR_dir_save = getDir player;
		_MMH2 = (findDisplay 46) displayAddEventHandler ["MouseMoving", {if(!isNil "FAR_revive_move")then{player setDir FAR_dir_save}}];
		_side_t = _this getVariable ["FAR_unit_Side", side _this];
		waitUntil {animationState player in [_b,"ainjppnemstpsnonwrfldnon"] || {time > _t1}};
		call FAR_Stabilize_code;
		_medic = player;
		_unit = _this;
		_t2 = time + _c;
		waitUntil {_check = (call FAR_Stabilize_Check1 || {FAR_CancelRevive}); (_check || {animationState _medic != _b} || {time > _t2})};
		call FAR_Stabilize_code1;
	};
};

FAR_HandleStabilize2 = {
	if (alive _this && {_this isKindOf "CaManBase"}) then {
		private ["_medic","_unit","_check","_side_t","_Sp","_MMH2","_X_Key","_medicName","_unitName"];
		_medicName = name player;
		_unitName = name _this;
		FAR_revive_move = 1;
		FAR_CancelRevive = false;
		FAR_remote_EH = [_this, player, "actDisable_debug", "AinvPknlMstpSnonWnonDnon_medicEnd"]; //
		_side_t = _this getVariable ["FAR_unit_Side", side _this];
		_this setVariable ["FAR_act_menu", false, true];
		publicVariable "FAR_remote_EH";
		inGameUISetEventHandler ["Action", "true"];
		FAR_dir_save = getDir player;
		_MMH2 = (findDisplay 46) displayAddEventHandler ["MouseMoving", {if(!isNil "FAR_revive_move")then{player setDir FAR_dir_save}}];
		call FAR_Stabilize_code;
		_medic = player;
		_unit = _this;
		call FAR_Stabilize2_code1;
		call FAR_Stabilize_code1;
	};
};

FAR_HandleStabilize3 = {
	if (alive _this && {_this isKindOf "CaManBase"} && {!(_this getVariable ["FAR_isStabilized",false])} && {player distance _this < 2}) then {
		_this setVariable ["FAR_isStabilized", true, true];
		_this setVariable ["FAR_StabilizeTime", [0,0], true];
		if (FAR_ReviveMode != 3 && {!("Medikit" in items player || {"Medikit" in items _this})}) then {
			[_this, player] call FAR_fn_removeFAK;
		};
	};
};

////////////////////////////////////////////////
// 拖动受伤的玩家
////////////////////////////////////////////////
FAR_DragMoves =	{
    animationState _this in [
	"amovpercmstpslowwrfldnon_acinpknlmwlkslowwrfldb_2","acinpknlmstpsraswrfldnon","acinpknlmwlksraswrfldb",
	"amovpercmstpsraswpstdnon_acinpknlmwlksnonwpstdb_2","acinpknlmstpsnonwpstdnon","acinpknlmwlksnonwpstdb",
	"amovpercmstpsnonwnondnon_acinpknlmwlksnonwnondb_2","acinpknlmstpsnonwnondnon","acinpknlmwlksnonwnondb"]
}; //步枪,手枪,空手 拖拉动作

FAR_DragWrongMoves = {
    animationState _this in [
	"helper_switchtocarryrfl","acinpknlmstpsraswrfldnon_acinpercmrunsraswrfldnon","acinpknlmstpsraswrfldnon_amovppnemstpsraswrfldnon","acinpercmrunsraswrfldnon","acinpercmrunsraswrfldf"]
}; //错误动作

FAR_DragProneMoves = {
    animationState _this in [
	//步枪,手枪,望远镜,空手 翻滚动作
	"amovppnemstpsraswrfldnon_amovppnemevaslowwrfldl","amovppnemstpsraswrfldnon_amovppnemevaslowwrfldr",
	"amovppnemstpsraswpstdnon_amovppnemevaslowwpstdl","amovppnemstpsraswpstdnon_amovppnemevaslowwpstdr",
	"amovppnemstpsoptwbindnon_amovppnemevasoptwbindl","amovppnemstpsoptwbindnon_amovppnemevasoptwbindr",
	"amovppnemstpsnonwnondnon_amovppnemevasnonwnondl","amovppnemstpsnonwnondnon_amovppnemevasnonwnondr",
	//步枪侧躺1
	"amovppnemstpsraswrfldnon_aadjppnemstpsraswrfldleft","aadjppnemstpsraswrfldleft", "aadjppnemwlksraswrfldleft_l","aadjppnemwlksraswrfldleft_r","amovppnemstpsraswrfldnon_aadjppnemstpsraswrfldright","aadjppnemstpsraswrfldright", "aadjppnemwlksraswrfldright_l","aadjppnemwlksraswrfldright_r","aadjppnemwlksraswrfldleft_f","aadjppnemwlksraswrfldleft_b","aadjppnemwlksraswrfldright_f","aadjppnemwlksraswrfldright_b",
	//手枪侧躺1
	"amovppnemstpsraswpstdnon_aadjppnemstpsraswpstdleft","aadjppnemstpsraswpstdleft","aadjppnemwlksraswpstdleft_l","aadjppnemwlksraswpstdleft_r", "amovppnemstpsraswpstdnon_aadjppnemstpsraswpstdright","aadjppnemstpsraswpstdright", "aadjppnemwlksraswpstdright_l","aadjppnemwlksraswpstdright_r","aadjppnemwlksraswpstdleft_f","aadjppnemwlksraswpstdright_f","aadjppnemwlksraswpstdright_b",
	//步枪侧躺2
	"amovppnemstpsraswrfldnon_aadjppnemstpsraswrflddown","aadjppnemstpsraswrflddown", "aadjppnemstpsraswrflddown_turnl","aadjppnemstpsraswrflddown_turnr",
	//手枪侧躺2
	"amovppnemstpsraswpstdnon_aadjppnemstpsraswpstddown","aadjppnemstpsraswpstddown", "aadjppnemstpsraswpstddown_turnl","aadjppnemstpsraswpstddown_turnr"]
}; //使趴下拖动能做战术动作自动放下

FAR_fn_MoveDone1 = {
	params ["_unit", "_Move", "_sel"];
    switch _sel do {
	    case 0 :{_unit switchMove _Move};
		case 1 :{_unit playMoveNow _Move};
		case 2 :{_unit playAction _Move};
	};
	waitUntil {_unit call FAR_DragMoves};
	FAR_Drag_MoveDone = true;
};
FAR_fn_MoveDone2 = {
	params ["_unit", "_Move1", "_Move2", "_sel"];
	_unit switchMove _Move1;
	waitUntil {animationState _unit == _Move1};
    switch _sel do {
		case 0 :{_unit playMoveNow _Move2};
		case 1 :{_unit playAction "grabDrag"};
	};
	waitUntil {animationState _unit == _Move2};
	FAR_Drag_MoveDone = true;
};
FAR_Drag_prone_keydown = {
	if ((_this select 1) in (actionKeys "moveForward" + actionKeys "moveFastForward") && {player == FAR_player}) exitWith {true};
	false
};

FAR_Drag = {
	if (isNull _this || {!(_this isKindOf "CaManBase")}) exitWith {TitleText ["无法拖动！", "Plain Down"]}; //
	private ["_id1", "_id2", "_id3", "_prone", "_KH"];
	
	FAR_player = player;
	FAR_isDragging = true;
	FAR_Release_Move = true;

	_this setVariable ["FAR_isDragged", true, true];
	_this setVariable ["FAR_stance", stance FAR_player, true];
	
	if (stance FAR_player == "PRONE") then [{
	    _prone = true;
	    _this attachTo [FAR_player, [0, 1.6, .092]];
		_KH = (findDisplay 46) displayAddEventHandler ["KeyDown", "_this call FAR_Drag_prone_keydown"];
	},{
	    _prone = false;
	    _this attachTo [FAR_player, [0, 1, .08]]; //[0, 1.1, .092]
		[_this, "switchMove", "AinjPpneMrunSnonWnonDb_still"] call FAR_remote_move;
	}];
	
	[_this, [180, "FAR_isDragged"]] call FAR_setDir; //旋转定位
	
	_id1 = FAR_player addAction [Format["<t color='#C90000'>%1</t>", localize "STR_far_put_down"], {FAR_isDragging = false}, [], 96, true, true, "", "_target == player"];
	_id2 = [FAR_player, Format["<t color='#C90000'>%1</t>", localize "STR_far_BanJinZaiJu"], "a3\ui_f\data\IGUI\Cfg\Cursors\getIn_ca.paa", "a3\ui_f\data\IGUI\Cfg\Cursors\getIn_ca.paa", "_target call FAR_Check_MoveIn", "_target call FAR_Check_MoveIn",{}, {}, {(FAR_remote_EH select 0) spawn FAR_in_veh}, {}, [], FAR_crewTime, 96, false, false, false] call BIS_fnc_holdActionAdd;
	_id3 = FAR_player addAction [Format["<t color='#C90000'>%1</t>", localize "STR_far_Carry"], {(FAR_remote_EH select 0) spawn FAR_Carry}, [], 96, false, true, "", "_target == player && {getPosASL FAR_player select 2 > -.4}"];
	
	hint "如果你无法移动请按C键，带有主武器时也可以按X键放下伤员。";
	
	FAR_Drag_MoveDone = true;
	waitUntil {
		if (FAR_Drag_MoveDone && {!(FAR_player call FAR_DragMoves)} && {!_prone} && {stance FAR_player != "PRONE"} && {getPosASL FAR_player select 2 > -.4}) then {
			FAR_Drag_MoveDone = false;
			FAR_player spawn {
			    if (primaryWeapon _this != "") then [{
				    if (currentWeapon _this == primaryWeapon _this) then [{
						[_this, "AcinPknlMstpSrasWrflDnon", 1] call FAR_fn_MoveDone1;
				    },{
				        _this selectWeapon (primaryWeapon _this);
						[_this, "amovpknlmstpsraswrfldnon", "AcinPknlMstpSrasWrflDnon", 0] call FAR_fn_MoveDone2;
				    }];
				},{
				    if (handGunWeapon _this != "") then [{
				        if (currentWeapon _this == handGunWeapon _this) then [{
							[_this, "grabDrag", 2] call FAR_fn_MoveDone1;
					    },{
					        _this selectWeapon (handGunWeapon _this);
							[_this, "amovpknlmstpsraswpstdnon", "acinpknlmstpsnonwpstdnon", 1] call FAR_fn_MoveDone2;
					    }];
				    },{
				        _this action ["hideWeapon", _this ,_this ,2];
						[_this, "amovpknlmstpsnonwnondnon", "acinpknlmstpsnonwnondnon", 1] call FAR_fn_MoveDone2;
				    }];
				}];
			};
		};

		( !alive FAR_player || {FAR_player getVariable ["FAR_isUnconscious",0] == 1} || {!alive _this} || {_this getVariable ["FAR_isUnconscious",0] == 0} || {!FAR_isDragging} || {!(_this getVariable ["FAR_isDragged",false])} || {_this getVariable ["FAR_isCarry",false]} || {vehicle _this != _this} || {vehicle FAR_player != FAR_player} || {_prone && {stance FAR_player != "PRONE"}} || {FAR_player call FAR_DragWrongMoves} || {FAR_player call FAR_DragProneMoves} )
	};
	
	FAR_isDragging = false;

	detach _this;
	
	if (vehicle FAR_player == FAR_player && {FAR_player getVariable ["FAR_isUnconscious",0] == 0} && {stance FAR_player != "PRONE"} && {alive FAR_player}) then 
	{
	    _pdownMove = if(primaryWeapon FAR_player != "")then[{if(FAR_Release_Move)then[{"amovpknlmstpsraswrfldnon"},{"amovpercmstpsraswrfldnon"}]},{if(handGunWeapon FAR_player != "")then[{if(FAR_Release_Move)then[{"amovpknlmstpsraswpstdnon"},{"amovpercmstpsraswpstdnon"}]},{FAR_player action ["hideWeapon", FAR_player ,FAR_player ,2];if(FAR_Release_Move)then[{"amovpknlmstpsnonwnondnon"},{"amovpercmstpsnonwnondnon"}]}]}];
		if(FAR_player call FAR_DragWrongMoves || {_this getVariable ["FAR_isCarry",false]})then[{sleep .5;FAR_player switchMove _pdownMove},{FAR_player playMoveNow _pdownMove}];
	};
	
	{FAR_player removeAction _x} forEach [_id1, _id2, _id3];
	
	if(!isNil {_KH})then{(findDisplay 46) displayRemoveEventHandler ["KeyDown", _KH]};
	
	if (!isNull _this && {alive _this}) then
	{
		if!(_this getVariable ["FAR_isCarry",false])then{[_this, "switchMove", "ainjppnemstpsnonwrfldnon"] call FAR_remote_move};
		_this setVariable ["FAR_isDragged", false, true];
	};
};

////////////////////////////////////////////////
// 扛起受伤的玩家
////////////////////////////////////////////////
FAR_carring_moves = {
    animationState _this in ["acinpercmstpsraswrfldnon","acinpercmrunsraswrfldf","acinpercmrunsraswrfldfr","acinpercmrunsraswrfldfl","acinpercmrunsraswrfldl","acinpercmrunsraswrfldr","acinpercmrunsraswrfldb","acinpercmrunsraswrfldbr","acinpercmrunsraswrfldbl"]
};

FAR_Carry = {
	if (isNull _this || {!(_this isKindOf "CaManBase")}) exitWith {};
	private ["_id1", "_id2"];

	FAR_player = player;
	FAR_isCarry = true;
	FAR_Release_Move = true;
	_this setVariable ["FAR_isCarry", true, true];
	_t1 = time + 5;
	waitUntil {!(_this getVariable ["FAR_isDragged",false]) || {!alive _this} || {time > _t1}};
	if (stance FAR_player == "PRONE") then {FAR_player playMoveNow "amovpknlmstpsraswrfldnon"; waitUntil {animationState FAR_player == "amovpknlmstpsraswrfldnon" || {!alive _this} || {time > _t1}}};
	if(!alive _this)exitWith{FAR_isCarry = false};
	[_this, "switchMove", "ainjpfalmstpsnonwnondnon_carried_up"] call FAR_remote_move;
	_this attachTo [FAR_player,[.05, 1.1, 0]];
	detach _this;
	[_this, [(getDir FAR_player + 180), "FAR_isCarry"]] call FAR_setDir;
	FAR_player selectWeapon (primaryWeapon FAR_player); //
	FAR_player switchMove "amovpercmstpslowwrfldnon";
	FAR_player playMoveNow "AcinPknlMstpSrasWrflDnon_AcinPercMrunSrasWrflDnon";
	
	_t3 = time + 14; //动作过渡时间 *13
	while {time < _t3 && {alive _this} && {alive FAR_player} && {vehicle FAR_player == FAR_player} && {FAR_player getVariable ["FAR_isUnconscious",0] == 0}} do {sleep .01}; //等待伤员完成动作
	if(!alive _this)exitWith{FAR_player switchMove "amovpercmstpsraswrfldnon"; FAR_isCarry = false};
	sleep .1;
	[_this, "switchMove", "ainjpfalmstpsnonwnondnon_carried_still"] call FAR_remote_move;
	sleep .1;
	_this attachTo [FAR_player,[-.26, .1, .1]]; //[-.15, .1, .1]
	
	_t4 = time + 8; //*3 bug
	waitUntil {animationState FAR_player == "acinpercmstpsraswrfldnon" || {!alive _this} || {!alive FAR_player} || {FAR_player getVariable ["FAR_isUnconscious",0] == 1} || {vehicle FAR_player != FAR_player} || {time > _t4}}; //等待玩家完成动作
	
	_id1 = FAR_player addAction [Format["<t color='#C90000'>%1</t>", localize "STR_far_put_down"], {FAR_isCarry = false}, [], 96, true, true, "", "_target == player"];
	_id2 = [FAR_player, Format["<t color='#C90000'>%1</t>", localize "STR_far_BanJinZaiJu"], "a3\ui_f\data\IGUI\Cfg\Cursors\getIn_ca.paa", "a3\ui_f\data\IGUI\Cfg\Cursors\getIn_ca.paa", "_target call FAR_Check_MoveIn", "_target call FAR_Check_MoveIn",{}, {}, {(FAR_remote_EH select 0) spawn FAR_in_veh}, {}, [], FAR_crewTime, 96, false, false, false] call BIS_fnc_holdActionAdd;
	
    while {FAR_isCarry && {alive FAR_player} && {FAR_player getVariable ["FAR_isUnconscious",0] == 0} && {alive _this} && {_this getVariable ["FAR_isUnconscious",0] == 1} && {_this getVariable ["FAR_isCarry",false]} && {vehicle _this == _this} && {vehicle FAR_player == FAR_player} && {FAR_player call FAR_carring_moves}} do {sleep .5}; //等待放下
	
	FAR_isCarry = false;
	
	if (vehicle FAR_player == FAR_player && {FAR_player getVariable ["FAR_isUnconscious",0] == 0} && {stance FAR_player != "PRONE"} && {alive FAR_player} && {getPosASL FAR_player select 2 > -.4}) then 
	{
	    FAR_player playMoveNow (if(FAR_Release_Move)then[{"amovpknlmstpsraswrfldnon"},{"amovpercmstpsraswrfldnon"}]);
	};
	
	{FAR_player removeAction _x} forEach [_id1, _id2];
	
	if (!isNull _this) then {
		if(!alive _this)exitWith{detach _this};
		_this attachTo [FAR_player,[.1, .1, 0]]; //
		detach _this;
		if (alive FAR_player && {FAR_player getVariable ["FAR_isUnconscious",0] == 0} && {FAR_player call FAR_carring_moves}) then
		[{
			[_this, "playMoveNow", "ainjpfalmstpsnonwnondnon_carried_down"] call FAR_remote_move;
			sleep 5;
			if(FAR_Release_Move)then{[_this, "switchMove", "ainjppnemstpsnonwrfldnon"] call FAR_remote_move};
		},{
			[_this, "switchMove", "ainjppnemstpsnonwrfldnon"] call FAR_remote_move;
		}];
		if (alive _this) then {_this setVariable ["FAR_isCarry", false, true]};
	};
};

//////////////////////////////////////////////////////////////////////////
// 其他函数
////////////////////////////////////////////////
FAR_veh_eh = {
    if (alive _this && {_this getVariable ["FAR_isUnconscious", 8] == 1} && {vehicle _this != _this}) then
    {
		if (driver vehicle _this == _this && {isEngineOn vehicle _this} && {local vehicle _this}) then 
		{
			vehicle _this engineOn false; //强制关闭引擎
		};
		
		if (!alive (vehicle _this) || {surfaceIsWater getPosASL _this && {(getPosASL (vehicle _this) select 2) < -2}} || {vehicle _this isKindOf "StaticWeapon"} || {vehicle _this isKindOf "Motorcycle"}) exitWith {_this spawn FAR_out_veh}; //或者在水里
		
		/*_role = "";
		_turretPath = [];
		_cargoIndex = 0;
		{if (_x select 0 == _this) exitWith {_role = _x select 1; _turretPath = _x select 3; _cargoIndex = _x select 2}} forEach fullCrew vehicle _this;
		if (_role == "driver" || {toLower _role in ["turret","gunner","commander"] && {_cargoIndex == -1} && {count(vehicle _this weaponsTurret _turretPath) != 0}}) then {*/
		_role = assignedVehicleRole _this;
		if (_role select 0 == "driver" || {_role select 0 == "Turret" && {count(vehicle _this weaponsTurret (_role select 1)) != 0}}) then {
			if (!isPlayer _this) then [{
				_this spawn FAR_out_veh;
			},{
				if (FAR_coerce_Spectator) then {FAR_coerce_Spectator = false};
				if (isNil "FAR_camera") then {
					FAR_Key_sw = false; //
					call FAR_F_Spectator;
					"当前载具位锁定在观战模式自由视角" call FAR_F_Text;
				};
			}];
		}; //当前载具位是否有武器
	};
}; //载具中的无意识单位

FAR_coerce_Move = {
	if (alive _this && {_this getVariable ["FAR_isUnconscious", 8] == 1} && {!(animationState _this in ["ainjppnemstpsnonwrfldnon_rolltoback",/*"ainjppnemstpsnonwrfldnon_injuredhealed",*/"ainjppnemstpsnonwrfldnon","ainjppnemstpsnonwrfldnon_rolltofront",FAR_creep_injured/*爬动*/,"ainjppnemrunsnonwnondb_still","ainjpfalmstpsnonwnondnon_carried_up","ainjpfalmstpsnonwnondnon_carried_down","ainjpfalmstpsnonwnondnon_carried_still"])}) then 
	{
		if (vehicle _this == _this) then [{
		    if !(_this getVariable ["FAR_isCarry",false]) then [{
			    if !(_this getVariable ["FAR_isDragged",false]) then [{
					if (animationState _this in ["acrgpknlmstpsnonwnondnon_amovpercmstpsraswrfldnon_getoutmedium","acrgpknlmstpsnonwnondnon_amovpercmstpsraswrfldnon_getouthighhemtt"]) then
					[{
					    _this switchMove "ainjppnemstpsnonwrfldnon";
					},{
					    _this playMoveNow "ainjppnemstpsnonwrfldnon_rolltoback";
					}];
				},{
				    _this playMoveNow (if(_this getVariable ["FAR_stance", ""] != "PRONE")then[{"ainjppnemrunsnonwnondb_still"},{"ainjppnemstpsnonwrfldnon_rolltoback"}]);
				}];
			},{
			    //_this switchMove "ainjpfalmstpsnonwnondnon_carried_still";
				[_this, "switchMove", "ainjpfalmstpsnonwnondnon_carried_still"] call FAR_remote_move;
			}];
		},{
			if (animationState _this != "getoutquadbike_cargo" && {animationState _this != "getoutquadbike"}) then {
			    _this playMoveNow "ainjppnemstpsnonwrfldnon_rolltoback";
			}; //载具内强制动作
		}];
	};
}; //无意识时强制动作

FAR_out_veh = {
	while {vehicle _this != _this && {alive _this}} do {
		//unAssignVehicle _this;
		_this action ["eject", vehicle _this];
		sleep .5;
		if(animationState _this in ["getoutquadbike_cargo","getoutquadbike"])then{sleep 1.6}; //debug
		if(vehicle _this==_this)exitWith{};
		_this action ["getout", vehicle _this];
		sleep .5;
		if(vehicle _this==_this)exitWith{};
		_this setPos (_this modelToWorld [0,0,0]);
	};
	if ((getPos _this select 2)>2) then {
        waitUntil {if(!alive _this)exitwith{true};_this setVelocity [0,0,-9999];sleep 0.1;(velocity _this select 2)<8 && {(getPos _this select 2)<2}};
		_this setVelocity [0,0,0];
	};
    if (_this getVariable ["FAR_isUnconscious", 0] == 1) then {_this switchMove "ainjppnemstpsnonwrfldnon"};
}; //从载具弹出伤员

FAR_in_veh = {
	FAR_Release_Move = false;
	FAR_isDragging = false;
	FAR_isCarry = false;
	_veh = FAR_emptyPos_veh select 0;
	sleep 2;
	if (_this getVariable ["FAR_isCarry",false]) then {sleep 3}; //while...
	if (FAR_player getVariable ["FAR_isUnconscious",0] == 1 || {isNull _this} || {!alive _this}) exitWith {};
	FAR_inveh_EH = [_this, _veh];
	publicVariable "FAR_inveh_EH";
	["FAR_inveh_EH", [_this, _veh]] call FAR_public_EH;
}; //把伤员搬进载具

FAR_Radio_hint1 = {
	if (isDedicated) exitWith {};
	//if ("ItemRadio" in assignedItems player) then [{player groupChat _this},{systemChat _this}];
	player globalChat _this;
};

FAR_fn_removeFAK = {
	params ["_tag", "_unit"];
	if ("FirstAidKit" in items _tag) then [{
		_tag removeItem "FirstAidKit";
		if (isPlayer _tag) then {[["急救箱(黄包) -1", "Plain Down"]] remoteExec ["TitleText", _tag]};
	},{
		_unit removeItem "FirstAidKit";
		if (isPlayer _unit && {alive _unit}) then {
			TitleText ["急救箱(黄包) -1", "Plain Down"];
			if !("FirstAidKit" in items _unit) then {
				_chat = selectRandom ["我没有医疗用品了.", "那是我最后的急救箱.", "需要更多的医疗用品.", "我的黄包用完了.", "没包了.", "兄弟你可悠着点，我没包了.", "我应该多找点黄包"];
				_str = format["%1: %2", name _unit,_chat];
				_str remoteExec ["FAR_Radio_hint1", side _unit];
				if(side _unit != side _tag)then{_str remoteExec ["FAR_Radio_hint1", side _tag]};
			};
		};
	}];
}; //删除黄包

FAR_fn_breath = {
	if (local _this && {_this getVariable ["FAR_isUnconscious", 0] == 1} && {surfaceIsWater getPosASL _this} && {(getPosASLW _this select 2) == (getPos _this select 2)} && {(getPosASLW _this select 2) < 0}) then {
		_pos = getPosASL _this;
		if ((_pos select 2) < -8) then {
			_pos set [2, -5];
			_this setPosASL _pos;
		};
		_this setOxygenRemaining 1;
	};
}; //水里防淹死

FAR_var_init = {
	_this setVariable ["FAR_isUnconscious", 0, true];
	_this setVariable ["FAR_isDragged", false, true];
	_this setVariable ["FAR_isCarry", false, true];
	_this setVariable ["FAR_once_eh", true, true];
	_this setVariable ["FAR_act_menu", true, true];
	_this setVariable ["FAR_unit_Side", nil, true];
	_this setVariable ["FAR_call_AI", objNull, true];
	_this setVariable ["FAR_reviveTime", [0,0], true];
	_this setVariable ["FAR_StabilizeTime", [0,0], true];
	_this setVariable ["FAR_isStabilized", false, true]; //
};

FAR_fn_AISET1 = {
	if (!isPlayer _this && {_this getVariable ["FAR_isUnconscious", 0] == 1} && {local _this}) then {
		if (FAR_Invincible) then {_this allowDamage false}; //
		_this setCaptive true;
		_this stop true;
		{_this disableAI _x} forEach ["MOVE","TARGET","AUTOTARGET","ANIM","CHECKVISIBLE"];
	};
};

FAR_fn_AISET2 = {
	_this allowDamage true;
	_this setCaptive false;
	_this stop false;
	{_this enableAI _x} forEach ["MOVE","TARGET","AUTOTARGET","ANIM","CHECKVISIBLE"];
};

FAR_Respawn_Init = {
	params ["_unit"];
	if (local _unit) then {
		if (isPlayer _unit) then [{
			_unit removeAllEventHandlers "HandleDamage"; //#
			_unit addEventHandler ["HandleDamage", FAR_HandleDamage_EH];
			_unit call FAR_var_init;
			_unit setVariable ["ace_sys_wounds_uncon", false];
			inGameUISetEventHandler ["Action", "false"]; //debug
			if (FAR_playableUnit) then [{_unit remoteExec ["FAR_fn_AISET2", 0]},{_unit setCaptive false}]; //
			FAR_isDragging = false;
			FAR_isCarry = false;
		},{
			if (FAR_playableUnit) then {
				_unit removeAllEventHandlers "HandleDamage";
				_unit addEventHandler ["HandleDamage", {if(FAR_playableUnit)then{_this call FAR_HandleDamage_EH}}];
				_unit call FAR_var_init;
				_unit remoteExec ["FAR_fn_AISET2", 0];
				[_unit] joinSilent (_unit getVariable ["FAR_before_group", group _unit]); //阵营debug
			};
		}];
		if (FAR_playableUnit && {!(_unit getVariable ["FAR_Respawn", true])}) then {
			FAR_ADD_EH_HD = [_unit];
			publicVariable "FAR_ADD_EH_HD"; //远程全局添加伤害处理
		};
	};
}; //重生初始化

FAR_fn_AIADDFAR = {
	{
		if (_x != player) then {
			_x removeAllEventHandlers "HandleDamage"; //
			_x addEventHandler ["HandleDamage", {if (FAR_playableUnit) then {_this call FAR_HandleDamage_EH}}]; //
		};
		
		if (!isPlayer _x && {local _x} && {_x getVariable ["FAR_Respawn", true]} && {alive _x}) then {
			_x call FAR_var_init;
			_x setVariable ["FAR_before_group", group _x, true];
			_x addMPEventHandler ["MPRespawn", {_this spawn FAR_Respawn_Init}]; ////
			_x setVariable ["FAR_Respawn", false, true]; ////
		};
	} forEach playableUnits;
};

FAR_fn_RespawnDebug = {
	while {true} do {
		waitUntil {!alive player};
		waitUntil {alive player};
		sleep 2; //
		if (player getVariable ["FAR_isUnconscious", 0] == 1) then {
			[player] call FAR_Respawn_Init;
			systemChat "FAR: 重生初始化失败！除错..";
		};
		private _anim = animationState player;
		if (_anim == "amovppnemstpsraswrfldnon_injured" || {_anim == "amovppnemsprslowwrfldf_injured"} || {_anim == "ainjppnemstpsnonwrfldnon"}) then {
			player switchMove "";
			systemChat "FAR: 重生卡动作！除错..";
		};
	};
}; //防止重生事件失效导致初始化失败

FAR_fn_joinGro = {
	params ["_ai","_tag_side","_t"];
	_ai_side = side _ai;
	if (_ai_side != _tag_side && {_tag_side != sideEnemy}) then {
		_grp1 = group _ai;
		_grp2 = createGroup [_tag_side, true];
		[_ai] joinSilent _grp2;
		sleep _t;
		if (alive _ai) then [{
			if (isNull _grp1) then [{
				_grp3 = createGroup [_ai_side, true];
				[_ai] joinSilent _grp3;
			},{
				[_ai] joinSilent _grp1;
			}];
			deleteGroup _grp2;
		},{
			deleteGroup _grp1;
		}];
	};
};

FAR_fn_AI_RS = {
	if ((!isPlayer _this || {!FAR_callAI_en}) && {local _this} && {time > _this getVariable ["FAR_AI_RS_t", 0]} && {_this getVariable ["FAR_isUnconscious",0] == 1} && {_this getVariable ["FAR_act_menu",true]} && {!(_this getVariable ["FAR_isDragged",false])} && {!(_this getVariable ["FAR_isCarry",false])} && {alive _this}) then {
		_this setVariable ["FAR_AI_RS_t", time + (5 + random 25)];
		private _side = _this getVariable ["FAR_unit_Side", side _this];
		[_this, _side] spawn FAR_callFriendlies_AI;
	};
};

k1_allUnits = {
	private ["_objs", "_obj"];
	_objs = [];
	{
		_obj = agent _x;
		if (alive _obj) then {_objs pushback _obj};
	} forEach agents;
	_objs append allUnits;
	_objs
};

k1_fn_ProgressBar = {
	params ["_t1","_t2","_size","_color","_H"];
	private ["_arr1","_arr2","_range1","_range2","_Divide","_str"];
	_arr1 = [];
	_Divide = _t2 / 100;
	_range1 = floor ((_t2 - _t1) / _Divide);
	_range2 = 100 - _range1;
	if (_range2 > 100) then {_range2 = 100};
	_arr1 resize _range2;
	_arr1 = _arr1 apply {"|"};
	if (_range1 > 0) then {
		_arr2 = [];
		_arr2 resize _range1;
		_arr2 = _arr2 apply {"."};
		_arr1 append _arr2;
	};
	_str = _arr1 joinString "";
	[format["<t size = '%1' color='%2'>%3 %4％</t>", _size,_color,_str,_range2],-1,_H * safeZoneH + safeZoneY,3,0,0,1976] spawn BIS_fnc_dynamicText;
	_range2
};

FAR_rs_progress = {
	params ["_t1","_t2"];
	private ["_Divide","_range1","_range2"];
	_Divide = _t2 / 100;
	_range1 = floor ((_t2 - _t1) / _Divide);
	_range2 = 100 - _range1;
	if (_range2 > 100) then {_range2 = 100};
	_range2
};

getUnitPositionId = {
	private ["_vvn", "_str"]; 
	_vvn = vehicleVarName _this; 
	_this setVehicleVarName ""; 
	_str = str _this; 
	_this setVehicleVarName _vvn; 
	parseNumber (_str select [(_str find ":") + 1])
};

FAR_rs_mod3Start = {
	FAR_target setVariable ["FAR_call_AI", player, true];
	FAR_target setVariable ["FAR_CallAI_X", true, true];
};

FAR_rs_mod3Close = {
	FAR_target setVariable ["FAR_call_AI", objNull, true];
};

/////////////////////////////////////////////////////////////////////////
// 专用服务器执行
////////////////////////////////////////////////
FAR_fn_isDedicated = {
	0 spawn {
		_time = 0;
		while {true} do {
			{
				_unit = _x select 0;
				if (local _unit) then {
					if (!FAR_playableUnit && {!isPlayer _unit}) then { //多人模式倒地AI debug
						_unit call FAR_var_init;
						_unit remoteExec ["FAR_fn_AISET2", 0];
						if(vehicle _unit == _unit)then{_unit switchMove 'deadstate'};
						_unit setDamage 1;
					};
					_unit call FAR_veh_eh; //载具损毁弹出无意识单位
					_unit call FAR_coerce_Move;
				};
				
				if (_unit getVariable ["FAR_isUnconscious", 0] == 0 || {!alive _unit}) then {
					FAR__units = FAR__units - [_x];
				};
			} forEach FAR__units;
			
			if (FAR_playableUnit && {time > _time}) then { //AI相关设置
				_time = time + 4;
				{(_x select 0) call FAR_fn_AISET1} forEach FAR__units;
			};
			
			if (FAR_playableUnit) then { {(_x select 0) call FAR_fn_breath} forEach FAR__units };
			
			if (FAR_AI_RS) then { {(_x select 0) call FAR_fn_AI_RS} forEach FAR__units };
			
			sleep 1;
		};
	};
	
	0 spawn { //多人模式AI添加FAR
		if (!FAR_playableUnit) exitWith {};
		uiSleep 5;
		call FAR_fn_AIADDFAR;
	};
};

///////////////////////////////////////////////////////////////////////////
// PV公布变量事件处理
////////////////////////////////////////////////
FAR_public_EH = {
	if(count _this < 2) exitWith {};
	params ["_EH", "_arr"];
	
	if (_EH == "FAR_deathMessage2") exitWith {
		_arr params ["_killed", "_killer", "_killedSide"];
		if (isPlayer _killer && {_killed != _killer}) then [{
			_emyend = " ?";
			_killsInfantry = 0;
			private _num = _killer getVariable ["FAR_count_kill", 0];
			_killer_side = _killer getVariable ["FAR_unit_Side", side _killer]; ////
			if((_killedSide getFriend _killer_side >= .6)&&{_killer_side getFriend _killedSide >= .6})then[{_killsInfantry = -1; _emyend = " (友军误伤)"; _num = _num - 1},{_killsInfantry = 1; _emyend = ""; _num = _num + 1}];
			if(FAR_EnableDeathMessages && {alive _killed})then{systemChat format["%1 击伤 %2%3", if(alive _killer)then[{name _killer},{"???"}], name _killed, _emyend]};
			if(player == _killer)then{_killer setVariable ["FAR_count_kill", _num, true]; [_killed,_killsInfantry] spawn FAR_KnockDown_script};
			
			if (!isMultiplayer) exitWith {}; //
			
			//计分板步兵击杀分数
			if (FAR_kill_Score && {player == _killer} && {_killsInfantry != 0}) then {
				if(_killer_side==sideEnemy)then{_killsInfantry=-1};
				[player, _killsInfantry] remoteExec ["FAR_addKillScores", 2];
			};
			
			//击伤友军
			if (FAR_killFriend && {player == _killer} && {isPlayer _killed} && {_killsInfantry == -1} && {player getVariable ["FAR_once_eh",true]}) then {
				FAR_killFriend_number = FAR_killFriend_number + 1;
				if (FAR_killFriend_number == FAR_allow_killFriend) then {['<t color="#FF0000" size=".6">连续击伤队友警告！注意敌我识别不要误伤队友！</t>',-1,.01 * safeZoneH + safeZoneY,15,0,0,7374] spawn BIS_fnc_dynamicText};
				if (FAR_killFriend_Check) then {FAR_killFriend_Check = false; [] spawn FAR_fn_killFriend};
			};
		},{
			if(FAR_EnableDeathMessages && {alive _killed})then{systemChat format["%1 倒下了，已经失去意识", name _killed]};
		}];
	};
	
	// 单位标记
	if (_EH == "FAR_Damage_make") exitWith {
		_arr spawn {
			params ["_unit", "_makeName"];
			if (({_unit in _x} count FAR__units) > 0) exitWith {};
			if (FAR_map_mak && {!isDedicated} && {player getVariable ["FAR_downMak_en", true]}) then {
				_unitSide = _unit getVariable ["FAR_unit_Side", side _unit];
				_plySide = player getVariable ["FAR_unit_Side", side player];
				if (((_unitSide getFriend _plySide >= .6) && {_plySide getFriend _unitSide >= .6}) || {!isNil "FAR_disable_Friend"}) then {
					_make = createMarkerLocal [_makeName, getPosASL _unit];
					_makeName setMarkerTypeLocal "hd_dot";
					_makeName setMarkerTextLocal (if(alive _unit)then[{name _unit},{"???"}]) + " 倒下";
					_makeName setMarkerColorLocal "ColorRed";
				};
			};
			FAR__units pushback _this;
		};
	};
	
	// 无意识单位进入载具
	if (_EH == "FAR_inveh_EH") exitWith {
		_unit = _arr select 0;
		if (local _unit) then {
		    _veh = _arr select 1;
			//_unit assignAsCargo _veh; //
			_unit moveInCargo _veh;
		};
		// AI离开组(防止被命令下车)
		if (!isMultiplayer && {!isPlayer _unit}) then {
			_unit setVariable ["FAR_AI_group", [true, group _unit, _unit call getUnitPositionId]]; //
			[_unit] joinSilent (createGroup [side _unit, true]);
		};
		// 无意识单位在载具的动作
		if (isMultiplayer) then {
			_unit spawn {
				_t2 = time+8;
				waitUntil {vehicle _this != _this || {!alive _this} || {_this getVariable ["FAR_isUnconscious",0] == 0} || {time > _t2}};
				if (vehicle _this == _this || {!alive _this} || {_this getVariable ["FAR_isUnconscious",0] == 0} || {time > _t2}) exitWith {};
				_this playMoveNow "ainjppnemstpsnonwrfldnon_rolltoback";
			};
		};
	};
	
	if (_EH == "FAR_ADD_EH_HD") exitWith {
		_arr params ["_unit"];
		_unit removeAllEventHandlers "HandleDamage";
		_unit addEventHandler ["HandleDamage", {if (FAR_playableUnit) then {_this call FAR_HandleDamage_EH}}];
	};//
};

//远程执行
FAR_remote_exec = {
	params ["", "_arr"];
	_arr  params ["_unit", "_play", "_command", "_parameter"];
	
	if (_command == "switchMove") exitWith {_unit switchMove _parameter};
	
	if (_command == "help_chat") exitWith {
		if (isDedicated) exitWith {};
		_side1 = _arr select 1;
		_side2 = player getVariable ["FAR_unit_Side", side player];
		if (alive _unit && {((_side1 getFriend _side2 >= .6) && {_side2 getFriend _side1 >= .6}) || {!isNil "FAR_disable_Friend"}} && {_unit getVariable ["FAR_isUnconscious", 0] == 1}) then {
			_parameter params ["_chat", "_medic"];
			_chat2 = if(player == _medic && {player getVariable ["FAR_once_eh", true]} && {alive player})then[{format[" （你离%1最近，只有%2m远）", name _unit, floor(player distance _unit)]},{""}];
			_chat3 = format["%1: %2%3", name _unit,_chat,_chat2];
			//if("ItemRadio" in assignedItems player)then[{player groupChat _chat3},{systemChat _chat3}];
			player globalChat _chat3;
		};
	}; //呼救
	
	if (_command == "setDir") exitWith {
		if (local _unit) then {_unit setDir (_parameter select 0)}; //
		_unit setVariable [(_parameter select 1), true]; //延迟debug "FAR_isDragged"
		_arr spawn {
			params ["_unit", "_play"];
			_parameter = (_this select 3) select 1;
			waitUntil {!(_unit getVariable [_parameter, false]) || {!alive _play} || {!alive _unit} || {!isPlayer _play}};
			sleep 2;
			if (!(_unit getVariable [_parameter, false]) || {alive _play && {isPlayer _play}}) exitWith {};
			if (alive _play) then {_play switchMove "amovpknlmstpsraswrfldnon"};
			if (local _play) then {detach _unit};
			if (local _unit && {alive _unit}) then {
				_unit switchMove "AinjPpneMstpSnonWrflDnon";
				_unit setVariable [_parameter, false, true];
			};
		};
	}; //拖拽&肩扛者死亡断线debug
	
	if (_command == "actDisable_debug") exitWith {
		_arr spawn {
			params ["_unit", "_play", "", "_parameter"];
			_unit setVariable ["FAR_act_menu", false];
			waitUntil {_unit getVariable ["FAR_act_menu", true] || {!alive _play} || {!alive _unit} || {!isPlayer _play}};
			sleep 2;
			if (_unit getVariable ["FAR_act_menu", true] || {alive _play && {isPlayer _play}}) exitWith {};
			if (alive _play) then {_play switchMove _parameter};
			if (local _unit && {alive _unit}) then {_unit setVariable ["FAR_act_menu", true, true]};
		};
	}; //隐藏医治菜单debug
	
	if (_command == "actDisable_debug2") exitWith {
		_arr spawn {
			params ["_play", "_ai", "", "_parameter"];
			_parameter params ["_time", "_anim"];
			_play setVariable ["FAR_act_menu", false];
			_time = time + _time;
			waitUntil {_play getVariable ["FAR_act_menu", true] || {!alive _ai} || {!alive _play} || {_ai distance _play > FAR_callAI_dist*1.4} || {time > _time}};
			if (_play getVariable ["FAR_act_menu", true]) exitWith {};
			if (alive _ai) then {_ai switchMove _anim};
			if (local _play && {alive _play}) then {_play setVariable ["FAR_act_menu", true, true]};
		};
	}; //AI医治debug
	
	if (local _unit) then {
		switch _command do {
			case "ReviveAI": {
				_unit remoteExec ["FAR_fn_AISET2", 0];
				if(FAR_ReviveMode != 4)then{_unit setDamage 0};
				_unit call FAR_UpwardMove;
			};
			case "outveh": {_unit spawn FAR_out_veh;}; //搬出伤员
			//转换动作
			case "playMove": {_unit playMove _parameter;};
			case "playMoveNow": {_unit playMoveNow _parameter;};
		};
	};
};

// Set dir
FAR_setDir = {
	params ["_unit", "_dir_vn"];
	FAR_remote_EH = [_unit, FAR_player, "setDir", _dir_vn];
	publicVariable "FAR_remote_EH";
	[nil, FAR_remote_EH] spawn FAR_remote_exec; //
};

// remote exec move
FAR_remote_move = {
	params ["_unit","_type","_move"];
	FAR_remote_EH = [_unit, nil, _type, _move];
	publicVariable "FAR_remote_EH";
	[nil, FAR_remote_EH] spawn FAR_remote_exec;
};


//////////////////////////////////////////////动作菜单检查////////////////////////////////////////////////
// 搬进载具动作菜单检查
////////////////////////////////////////////////
FAR_Check_MoveIn = {
	if (stance player == "PRONE" || {_this != player} || {vehicle player != player}) exitWith {false};
	FAR_emptyPos_veh = [];
	{
		if (alive _x && {_x emptyPositions "Cargo" > 0}) then {FAR_emptyPos_veh pushback _x};
	} forEach (nearestObjects[player,["car","Tank","Helicopter","Plane","ship","Motorcycle"],9]); //5
	if (count FAR_emptyPos_veh > 0) exitWith {true};
	false
};

////////////////////////////////////////////////
// 搬出载具动作菜单检查
////////////////////////////////////////////////
FAR_Check_MoveOut = {
	private _target = cursorTarget;
	if (isNull _target) then {
		_nearVehs = nearestObjects [player, ["car","Tank","Helicopter","Plane","ship","Motorcycle"], 9]; //5
		_target = if (count _nearVehs > 0)then [{_nearVehs select 0},{objNull}];
	};

	if ( isNull _target || {(_target distance player) > 9} || {!(_target isKindOf "car" || {_target isKindOf "Tank"} || {_target isKindOf "Helicopter"} || {_target isKindOf "Plane"} || {_target isKindOf "ship"} || {_target isKindOf "Motorcycle"})} || {count crew _target == 0} || {vehicle player != player} || {FAR_isDragging} || {FAR_isCarry} || {stance player == "PRONE"} || {player getVariable ["FAR_isUnconscious",0] == 1} || {!alive player} ) exitWith {false};
	
	FAR_veh_crew = [];
	{
		if (_x getVariable ["FAR_isUnconscious", 0] == 1 && {alive _x}) then {FAR_veh_crew pushback _x};
	} forEach crew _target;
	
	if (count FAR_veh_crew > 0) exitWith {true};

	false
};
////////////////////////////////////////////////
// 杀死目标动作菜单检查
////////////////////////////////////////////////
FAR_Check_killAct = {
	if (!FAR_allow_kill) exitWith {false};
	
	private _target = cursorTarget;
	if (isNull _target) then {
		_nearUnits = nearestObjects [player, ["CaManBase"], 2] - [player];
		_target = if(count _nearUnits > 0)then[{_nearUnits select 0},{objNull}];
	};
	
	if (isNull _target || {!(_target isKindOf "CaManBase")} || {(_target distance player) > 2} || {!alive _target}) exitWith {false};

	_side_p = player getVariable ["FAR_unit_Side", side player];
	_side_t = _target getVariable ["FAR_unit_Side", side _target];
	if ( FAR_isDragging || {(_side_p getFriend _side_t >= .6) && {_side_t getFriend _side_p >= .6}} || {vehicle player != player} || {FAR_isCarry} || {player call FAR_DragProneMoves} || {player getVariable ["FAR_isUnconscious",0] == 1} || {!alive player} || {vehicle _target != _target} ) exitWith {false};
	
	if (_target getVariable ["FAR_isUnconscious", 0] == 1 && {!(_target getVariable ["FAR_isDragged", false])} && {!(_target getVariable ["FAR_isCarry", false])} && {_target getVariable ["FAR_act_menu", true]}) exitWith {FAR_target = _target; true};
	
	false
};
////////////////////////////////////////////////
// 医治动作菜单检查
////////////////////////////////////////////////
FAR_Check_Revive = {
	private _target = cursorTarget;
	if (isNull _target) then {
		_nearUnits = nearestObjects [player, ["CaManBase"], 2] - [player];
		_target = if (count _nearUnits > 0)then [{_nearUnits select 0},{objNull}];
	};

	if ( isNull _target || {!(_target isKindOf "CaManBase")} || {(_target distance player) > 2} || {vehicle player != player} || {FAR_isDragging} || {FAR_isCarry} || {FAR_ReviveMode == 2 && {!("Medikit" in items player || {"Medikit" in items _target})}} || {FAR_ReviveMode == 3 && {!(("FirstAidKit" in items player) || {"FirstAidKit" in items _target} || {"Medikit" in items player} || {"Medikit" in items _target})}} || {!FAR_water_rs && {getPosASL player select 2 < -.4}} || {player getVariable ["FAR_isUnconscious",0] == 1} || {!alive player} || {!alive _target} || {vehicle _target != _target} ) exitWith {false};
	
	if ( _target getVariable ["FAR_isUnconscious", 0] == 1 && {!(_target getVariable ["FAR_isDragged", false])} && {!(_target getVariable ["FAR_isCarry", false])} && {_target getVariable ["FAR_act_menu", true]} && {FAR_ReviveMode > 0 || {(getNumber (configfile >> "CfgVehicles" >> typeOf player >> "attendant")) == 1}} ) exitWith {FAR_target = _target; true};
	
	false
};
/////////////医治(黄包)//////////////
FAR_Check_Revive2 = {
	if (FAR_ReviveMode != 4) exitWith {false};
	
	private _target = cursorTarget;
	if (isNull _target) then {
		_nearUnits = nearestObjects [player, ["CaManBase"], 2] - [player];
		_target = if (count _nearUnits > 0)then [{_nearUnits select 0},{objNull}];
	};

	if( isNull _target || {!(_target isKindOf "CaManBase")} || {(_target distance player) > 2} || {damage _target < .35 && {_target getHit "hands" < .35} && {_target getHit "legs" < .35}} || {"Medikit" in items player} || {"Medikit" in items _target} || {vehicle player != player} || {FAR_isDragging} || {FAR_isCarry} || {!FAR_water_rs && {getPosASL player select 2 < -.4}} || {player getVariable ["FAR_isUnconscious",0] == 1} || {!alive player} || {!alive _target} || {vehicle _target != _target} ) exitWith {false};
	
	if ( _target getVariable ["FAR_isUnconscious", 0] == 1 && {!(_target getVariable ["FAR_isDragged", false])} && {!(_target getVariable ["FAR_isCarry", false])} && {_target getVariable ["FAR_act_menu", true]} && {"FirstAidKit" in items player || {"FirstAidKit" in items _target}} ) exitWith {FAR_target = _target; true};
	
	false
};
////////////////////////////////////////////////
// 止血动作菜单检查
////////////////////////////////////////////////
FAR_Check_Stabilize = {
	private _target = cursorTarget;
	if (isNull _target) then {
		_nearUnits = nearestObjects [player, ["CaManBase"], 2] - [player];
		_target = if (count _nearUnits > 0)then [{_nearUnits select 0},{objNull}];
	};
	
	if ( isNull _target || {!(_target isKindOf "CaManBase")} || {(_target distance player) > 2} || {FAR_ReviveMode in [1,4]} || {FAR_BleedOut <= 0} || {vehicle player != player} || {FAR_isDragging} || {FAR_isCarry} || {FAR_ReviveMode == 0 && {(getNumber (configfile >> "CfgVehicles" >> typeOf player >> "attendant")) == 1}} || {FAR_ReviveMode == 3 && {"FirstAidKit" in items player || {"FirstAidKit" in items _target}}} || {FAR_ReviveMode in [2,3] && {"Medikit" in items player || {"Medikit" in items _target}}} || {!FAR_water_rs && {getPosASL player select 2 < -.4}} || {player getVariable ["FAR_isUnconscious",0] == 1} || {!alive player} || {!alive _target} || {vehicle _target != _target} ) exitWith {false};
	
	if ( _target getVariable ["FAR_isUnconscious", 0] == 1 && {!(_target getVariable ["FAR_isStabilized", false])} && {!(_target getVariable ["FAR_isDragged", false])} && {!(_target getVariable ["FAR_isCarry", false])} && {_target getVariable ["FAR_act_menu", true]} && {"FirstAidKit" in items player || {"FirstAidKit" in items _target} || {"Medikit" in items player} || {"Medikit" in items _target} || {FAR_ReviveMode == 3}} ) exitWith {FAR_target = _target; true};
	
	false
};

////////////////////////////////////////////////
// 拖拽动作菜单检查
////////////////////////////////////////////////
FAR_Check_Dragging = {
	private _target = cursorTarget;
	if (isNull _target) then {
		_nearUnits = nearestObjects [player, ["CaManBase"], 2] - [player];
		_target = if (count _nearUnits > 0)then [{_nearUnits select 0},{objNull}];
	};

	if ( isNull _target || {!(_target isKindOf "CaManBase")} || {(_target distance player) > 2} || {vehicle player != player} || {FAR_isDragging} || {FAR_isCarry} || {player call FAR_DragProneMoves} || {player getVariable ["FAR_isUnconscious",0] == 1} || {!alive player} || {!alive _target} || {vehicle _target != _target} ) exitWith {false};
	
	if(_target getVariable ["FAR_isUnconscious", 0] == 1 && {!(_target getVariable ["FAR_isDragged", false])} && {!(_target getVariable ["FAR_isCarry", false])} && {_target getVariable ["FAR_act_menu", true]}) exitWith {FAR_target = _target; true};
	
	false
};

////////////////////////////////////////////////
// 扛起动作菜单检查
////////////////////////////////////////////////
FAR_Check_Carry = {
	private _target = cursorTarget;
	if (isNull _target) then {
		_nearUnits = nearestObjects [player, ["CaManBase"], 2] - [player];
		_target = if (count _nearUnits > 0) then [{_nearUnits select 0},{objNull}];
	};

	if ( isNull _target || {!(_target isKindOf "CaManBase")} || {(_target distance player) > 2} || {vehicle player != player} || {FAR_isDragging} || {FAR_isCarry} || {player call FAR_DragProneMoves} || {getPosASL player select 2 < -.4} || {player getVariable ["FAR_isUnconscious",0] == 1} || {!alive player} || {!alive _target} || {vehicle _target != _target} ) exitWith {false};
	
	if(_target getVariable ["FAR_isUnconscious", 0] == 1 && {!(_target getVariable ["FAR_isDragged", false])} && {!(_target getVariable ["FAR_isCarry", false])} && {_target getVariable ["FAR_act_menu", true]}) exitWith {FAR_target = _target; true};
	
	false
};

//////////////////////////////////////////////////////////////////////////////////////////////////////
// 附近友军医护兵
////////////////////////////////////////////////
FAR_IsFriendlyMedic = {
	private _return = false;
	params ["_unit", "_side"];
	
	if (alive _unit && {if(isMultiplayer)then[{isPlayer _unit},{_unit in (units player)}]} && {_side getFriend side _unit >= .6} && {side _unit getFriend _side >= .6} && {_unit getVariable ["FAR_isUnconscious", 0] == 0} && {lifeState _unit != "INCAPACITATED"} && {!(["UAV_AI", typeOf _unit] call BIS_fnc_inString)}) then
	{
		_return = switch FAR_ReviveMode do {
			case 0: { (getNumber (configfile >> "CfgVehicles" >> typeOf _unit >> "attendant")) == 1 || {!(player getVariable ["FAR_isStabilized",false]) && {FAR_BleedOut > 0} && {"FirstAidKit" in items _unit || {"FirstAidKit" in items player} || {"Medikit" in items _unit} || {"Medikit" in items player}}} };
			case 1: {true};
			case 2: { "Medikit" in items _unit || {"Medikit" in items player} || {!(player getVariable ["FAR_isStabilized",false]) && {FAR_BleedOut > 0} && {"FirstAidKit" in items _unit || {"FirstAidKit" in items player}}} };
			case 3: { "FirstAidKit" in items _unit || {"FirstAidKit" in items player} || {"Medikit" in items _unit} || {"Medikit" in items player} || {!(player getVariable ["FAR_isStabilized",false]) && {FAR_BleedOut > 0}} };
			case 4: {true};
			default {false};
		};
	};
	_return
};

FAR_min_dist = {
	private ["_unit", "_dist2"];
	params ["_medics", "_dist"];
	_unit = objNull;
	{
		_dist2 = player distance _x;
		if (_dist2 < _dist) then {
			_unit = _x;
			_dist = _dist2;
		};
	} forEach _medics;
	_unit
};

FAR_CheckFriendlies = {
	private ["_unit", "_units", "_medics", "_hintMsg", "_ai", "_str"];
	
	_units = nearestObjects [player, ["CaManBase", "LandVehicle", "Air", "Ship"], 500] - [player];
	_medics = [];
	_hintMsg = "";
	{
		if (_x isKindOf "CaManBase") then [{
			if ([_x, _this] call FAR_IsFriendlyMedic) then {_medics pushback _x};
		},{
			if (alive _x && {count crew _x > 0}) then {
				{
					if ([_x, _this] call FAR_IsFriendlyMedic) then {_medics pushback _x};
				} forEach crew _x;
			};
		}];
	} forEach _units;
	
	_ai = player getVariable ["FAR_call_AI", objNull];
	if (alive _ai && {!isPlayer _ai}) then {
		_medics pushback _ai;
		if (player getVariable ["FAR_act_menu",true]) then {
			_str = if(primaryWeapon _ai == "" && {handGunWeapon _ai == ""} && {secondaryWeapon _ai == ""})then[{""},{format["，F键%1交战", (if(player getVariable ["FAR_DISABLE_ATAG", false])then[{"允许"},{"禁止"}])]}];
			[format["<t size = '.8'>医护兵 %1(AI): 我已经在路上 (%2m)<br/>按X键取消%3</t>", name _ai, floor(_ai distance player), _str],-1,0,4,0,0,7374] spawn BIS_fnc_dynamicText;
		};
	};
	
	if (count _medics > 0) then [{
		_unit = [_medics, 500] call FAR_min_dist;
		FAR_near_medic = _unit;
		if (alive _unit) then {
			_unitName = name _unit;
			_distance = floor (player distance _unit);
			_hintMsg = format ["最近的医护兵:%1%2距离你%3m远", (if(FAR_Key_sw)then[{"<br/>"},{"\n"}]), _unitName, _distance];
		};
	},{
		_hintMsg = "沒有医护兵在附近";
		FAR_near_medic = objNull;
	}];
	
	_hintMsg
};

///////////////////////////////////////////////////////////////////////////////////////////////////
//AI医治目标单位
////////////////////////////////////////////////
FAR_Revive_AI = {
	params ["_ai","_tag","_side_t"];
	(_ai call FAR_medic_anim) params ["_a","_b","_c"];
	private ["_check","_medicName","_unitName"];
	_medicName = name _ai;
	_unitName = name _tag;
	_time_revive1 = time + 5;
	FAR_remote_EH = [_tag, _ai, "actDisable_debug2", [10,_a]];
	_ai playMoveNow _b;
	_tag setVariable ["FAR_act_menu", false, true];
	publicVariable "FAR_remote_EH";
	waitUntil {animationState _ai in [_b,"ainjppnemstpsnonwrfldnon"] || {time > _time_revive1}};
	format["%1(AI) 正在救治 %2", _medicName, _unitName] remoteExec ["systemChat", _side_t];
	if (FAR_join_side && {alive _ai}) then {[_ai, _side_t, 60] spawn FAR_fn_joinGro};
	_medic = _ai;
	_unit = _tag;
	_time_Minimum = time;
	_time_revive2 = time + _c;
    waitUntil {_check = (call FAR_Revive_Check1 || {[_ai,_tag] call FAR_callAI_checkCond}); (_check || {animationState _ai != _b} || {time > _time_revive2})};
	_isDownMove = (animationState _ai == "ainjppnemstpsnonwrfldnon");
	_isDownMove2 = (animationState _ai == "unconscious");
	if (_check || {_isDownMove} || {_isDownMove2} || {time - _time_Minimum < 5} || {vehicle _ai != _ai}) exitWith {
		_tag setVariable ["FAR_act_menu", true, true];
		if (!_isDownMove && {!_isDownMove2} && {vehicle _ai == _ai} && {lifeState _ai != "INCAPACITATED"})then {[_ai, "switchMove", _a] call FAR_remote_move}; //
		format["%1(AI) 没有救起 %2", _medicName, _unitName] remoteExec ["systemChat", _side_t];
		_ai setUnitPos "AUTO";
	};
	call FAR_Revive_code1;
	sleep .7; //1
	if (animationState _ai == _b || {time > _time_revive2}) then {_ai switchMove _a};
	_ai setUnitPos "AUTO";
};

FAR_Revive2_AI = {
	params ["_ai","_tag","_side_t"];
	private ["_check","_isDownMove","_Rp","_medicName","_unitName"];
	_medicName = name _ai;
	_unitName = name _tag;
	_tag setVariable ["FAR_act_menu", false, true];
	FAR_remote_EH = [_tag, _ai, "actDisable_debug2", [FAR_reviveTime+4,"AinvPknlMstpSnonWnonDnon_medicEnd"]];
	publicVariable "FAR_remote_EH";
	format["%1(AI) 正在救治 %2", _medicName, _unitName] remoteExec ["systemChat", _side_t];
	if (FAR_join_side && {alive _ai}) then {[_ai, _side_t, FAR_reviveTime+60] spawn FAR_fn_joinGro};
	_medic = _ai;
	_unit = _tag;
	call FAR_Revive2_code1;
	if (_Rp < 100 && {_check || {_isDownMove} || {animationState _ai == "unconscious"} || {vehicle _ai != _ai}}) exitWith {
		_tag setVariable ["FAR_act_menu", true, true];
		format["%1(AI) 没有救起 %2", _medicName, _unitName] remoteExec ["systemChat", _side_t];
		_ai setUnitPos "AUTO";
	};
	call FAR_Revive_code1;
	_ai setUnitPos "AUTO";
};
////////////////////////////////////////////////
// AI止血
////////////////////////////////////////////////
FAR_Stabilize_AI = {
	params ["_ai","_tag","_side_t"];
	(_ai call FAR_medic_anim) params ["_a","_b","_c"];
	private ["_t1","_t2","_check","_medicName","_unitName"];
	_medicName = name _ai;
	_unitName = name _tag;
	_t1 = time + 5;
	FAR_remote_EH = [_tag, _ai, "actDisable_debug2", [10, _a]];
	_ai playMoveNow _b;
	_tag setVariable ["FAR_act_menu", false, true];
	publicVariable "FAR_remote_EH";
	waitUntil {animationState _ai in [_b,"ainjppnemstpsnonwrfldnon"] || {time > _t1}};
	format["%1(AI) 正在给 %2 止血.", _medicName, _unitName] remoteExec ["systemChat", _side_t];
	_medic = _ai;
	_unit = _tag;
	_t2 = time + _c;
	waitUntil {_check = (call FAR_Stabilize_Check1 || {if(player == _medic)then[{FAR_CancelRevive},{false}]}); (_check || {animationState _ai != _b} || {time > _t2})};
	call FAR_Stabilize_code1;
};

FAR_Stabilize2_AI = {
	params ["_ai","_tag","_side_t"];
	private ["_check","_Sp","_medicName","_unitName"];
	_medicName = name _ai;
	_unitName = name _tag;
	_tag setVariable ["FAR_act_menu", false, true];
	FAR_remote_EH = [_tag, _ai, "actDisable_debug2", [FAR_StabilizeTime+4, "AinvPknlMstpSnonWnonDnon_medicEnd"]];
	publicVariable "FAR_remote_EH";
	format["%1(AI) 正在给 %2 止血.", _medicName, _unitName] remoteExec ["systemChat", _side_t];
	_medic = _ai;
	_unit = _tag;
	call FAR_Stabilize2_code1;
	call FAR_Stabilize_code1;
};
////////////////////////////////////////////////////////
// 呼叫AI治疗
////////////////////////////////////////////////
FAR_CallAiText1 = {
	private _str = if(primaryWeapon _this == "" && {handGunWeapon _this == ""} && {secondaryWeapon _this == ""})then[{""},{format["，F键%1交战", (if(player getVariable ["FAR_DISABLE_ATAG", false])then[{"允许"},{"禁止"}])]}];
	[format["<t size = '.8'>医护兵 %1(AI): 等一会，我正在路上<br/>按X键取消%2</t>", if(alive _this)then[{name _this},{"???"}], _str],-1,0,4,0,0,7374] spawn BIS_fnc_dynamicText;
};

FAR_CallAiText2 = {
	params ["_tag", "_ai"];
	if (player == _tag) then {[format["<t size = '.8'>医护兵 %1(AI): 取消医治</t>", if(alive _ai)then[{name _ai},{"???"}]],-1,0,4,0,0,7374] spawn BIS_fnc_dynamicText};
};

FAR_SETAIAUTOTARGET = {
	if (_this) then [{
		if (_ai getVariable ["FAR_AI_AUTOTARGET", true]) then {{_ai disableAI _x} forEach ["AUTOTARGET","TARGET"]; _ai doWatch objNull; _ai setVariable ["FAR_AI_AUTOTARGET", false]};
	},{
		if !(_ai getVariable ["FAR_AI_AUTOTARGET", true]) then {{_ai enableAI _x} forEach ["AUTOTARGET","TARGET"]; _ai setVariable ["FAR_AI_AUTOTARGET", true]};
	}];
};

FAR_enemy_visible = {
	private ["_enemy", "_check"];
	_enemy = _this findNearestEnemy _this;
	_check = (!isNull _enemy && {[vehicle _this, "VIEW",_enemy] checkVisibility [eyePos vehicle _this, eyePos _enemy] > 0});
	_check
};

FAR_closeFN = {
	{_ai enableAI _x} forEach ["MOVE","AUTOTARGET","TARGET"]; _ai stop false; //"ANIM",
	_grp = group _ai;
	if (_command == "" && {count units _ai > 1}) then [{
		_ai doFollow (leader _grp); //返回编队
	},{
		_ai doMove _previousPos;
		_ai moveTo _previousPos;
	}];
	//_ai setBehaviourStrong _Behaviour;
	if (!(_veh isKindOf "CaManBase") && {!(_veh isKindOf "StaticWeapon")} && {alive _veh}) then {_grp addVehicle _veh}; ////
	if (_veh isKindOf "StaticWeapon" && {alive _veh}) then {_ai assignAsGunner _veh; [_ai] orderGetIn true};
	_ai setVariable ["FAR_CallAiRevive", false,true];
	if (_ai == _tag getVariable ["FAR_call_AI", objNull]) then {_tag setVariable ["FAR_call_AI", objNull,true]};
	
	if (_veh isKindOf "Ship") then {_time4 = time + 300; waitUntil {_c1 = {alive _x} count _crew; _c2 = {alive _x && {_x in _crew}} count crew _veh; (_c1 == _c2) || {_driver != _ai && {(_c1-_c2) == 1}} || {time > _time4} || {!alive _veh}}; sleep 5; _driver enableAI "MOVE"; _qh = if(surfaceIsWater getPosASL _tag && {surfaceIsWater ([_veh, 60, getDir _veh] call BIS_fnc_relPos)})then [{20},{-20}]; _ai doMove ([_veh, _qh, getDir _veh] call BIS_fnc_relPos); if (!surfaceIsWater ([_veh, 30, getDir _veh] call BIS_fnc_relPos)) then {_time5 = time + 30; waitUntil {_c1 = {alive _x} count _crew; _c2 = {alive _x && {_x in _crew}} count crew _veh; (_c1 == _c2) || {time > _time5} || {!alive _veh}}; _dir = (getDir _veh)-180; [_veh, _dir] remoteExec ["setDir", 0]; sleep 1; [_veh,[0+(sin _dir*6),0+(cos _dir*6),((velocity _veh) select 2)]] remoteExec ["setVelocity", _veh]}}; //船debug
	
	_grp setSpeedMode _grpSpeed;
};

FAR_doMove_Revive = {
	private ["_ai", "_tag", "_side", "_moveTimeout", "_moveTimeout2", "_Stabi", "_check", "_dist", "_veh", "_pos", "_dist2", "_dist3", "_driver", "_crew", "_grpSpeed", "_Behaviour", "_command", "_previousPos", "_newPos", "_newPos2", "_enemy", "_Kit", "_ASCW"];
	_ai = _this select 0;
	if (!alive _ai || {_ai getVariable ["FAR_CallAiRevive", false]}) exitWith {};
	_tag = _this select 1;
	_side = _this select 2;
	_Stabi = _this select 3;
	_time1 = 0;
	_time2 = 0;
	_time3 = 0;
	_dist2 = 0;
	_Slow_speed = 0;
	_veh = vehicle _ai;
	_driver = driver _veh;
	_crew = crew _veh;
	_moveTimeout = time + 300;
	_moveTimeout2 = time + 60;
	_command = currentCommand _ai; //
	//_Behaviour = behaviour _ai;
	_grpSpeed = speedMode (group _ai);
	_fatEff	= .4;
	_GV0MaxP = .75;
	_GV0MaxC = .9;
	_throwTheta = 45;
	_Throw = selectRandom [1,2];
	_previousPos = if(surfaceIsWater getPosASL _ai)then[{getPosASL _ai},{getPosATL _ai}]; //
	_callAI_dist = if(FAR_callAI_dist > 150)then[{FAR_callAI_dist - 100},{FAR_callAI_dist}];
	_tag setVariable ["FAR_CallAI_X", false];
	_tag setVariable ["FAR_call_AI", _ai,true];
	_tag setVariable ["FAR_DISABLE_ATAG", nil];
	_tag setVariable ["FAR_CallAI_Smoke", nil];
	_ai setVariable ["FAR_CallAiRevive", true,true];
	_ai setVariable ["FAR_AI_animStuck", nil];
	_ai setVariable ["FAR_Throw_Smoke", nil];
	_ai setVariable ["FAR_AI_AUTOTARGET", nil];
	if(isPlayer _tag)then{_ai remoteExec ["FAR_CallAiText1", _tag]};
	_ai stop false;
	_ai disableAI "MOVE";
	sleep 3;
	_ai enableAI "MOVE";
	
	waitUntil {
		_dist3 = _ai distance _tag;
		_pos = if(surfaceIsWater getPosASL _tag)then [{getPosASL _tag},{getPosATL _tag}];
		if ((time > _time2 || {_ai distance _tag > _dist2}) && {lifeState _ai != "INCAPACITATED"}) then {
			_enemy = _ai findNearestEnemy _ai; //包含载具
			/*if (behaviour _ai in ["STEALTH", "COMBAT"]) then {
				if (!isNull _enemy) then [{
					_ai setBehaviourStrong (if(([_ai, "VIEW", _enemy] checkVisibility [eyePos _ai, eyePos _enemy]) > 0)then[{"COMBAT"},{"AWARE"}]); //arma3 1.92
				},{
					_ai setBehaviourStrong "CARELESS"; //“粗心大意”行为有助于AI快速过来救治
				}];
			};*/
			_ai allowFleeing 0;
			_ai doMove _pos; //全部队员移动到指定位置 _ai move _pos;
			_ai moveTo _pos; //
			(group _ai) setSpeedMode "FULL";
			_dist2 = _ai distance _tag;
			if (_ai == vehicle _ai && {!(_ai getVariable ["FAR_AI_AUTOTARGET", true]) || {isNull _enemy} || {[_ai, "VIEW", _enemy] checkVisibility [eyePos _ai, eyePos _enemy] == 0}}) then {
				_stance = stance _ai;
				if (_stance == "UNDEFINED" && {(getPosASLW _ai select 2) != (getPos _ai select 2)}) exitWith {[_ai, "switchMove", ""] call FAR_remote_move};
				if (_stance == "CROUCH" && {_dist2 > 150}) exitWith {_ai setUnitPos "UP"; _ai playAction "PlayerStand"};
				if (_stance == "PRONE" && {_dist2 > 35}) then {_ai setUnitPos "MIDDLE"};
			};
			_time2 = time + 30;
		};
		
		(if(primaryWeapon _ai == "" && {handGunWeapon _ai == ""} && {secondaryWeapon _ai == ""} && {isNull objectParent _ai})then[{true},{if(isPlayer _tag)then[{_tag getVariable ["FAR_DISABLE_ATAG", false]},{FAR_DISABLE_ATAG}]}]) call FAR_SETAIAUTOTARGET; //
		
		_ASCW = (animationState _ai == "ainvpknlmstpslaywrfldnon_medic" && {currentWeapon _ai in ["","Throw"]});
		if ((_ASCW && {damage _ai < .3}) || {_ai getVariable ["FAR_AI_animStuck", 0] > 4}) then [{
			_ai switchMove "amovpknlmstpsnonwnondnon";
			_ai setVariable ["FAR_AI_animStuck", 0];
		},{
			if (_ASCW) then {_ai setVariable ["FAR_AI_animStuck", (_ai getVariable ["FAR_AI_animStuck", 0]) + 1]};
		}];
		
		sleep 2;
		
		//平民应该设置与玩家敌对阵营不友好
		if (_ai distance _tag < 22 && {stance _ai != "PRONE"} && {isNull objectParent _ai} && {!isNull (_ai findNearestEnemy _ai)} && {[_ai, "VIEW", (_ai findNearestEnemy _ai)] checkVisibility [eyePos _ai, eyePos (_ai findNearestEnemy _ai)] > 0}) then {_ai setUnitPos "DOWN"};
		
		if (vehicle _ai != _ai) then [{
			_dist = if(_veh isKindOf "Helicopter")then[{500},{if(_veh isKindOf "Ship")then[{50},{15}]}];
			
			if (!(_veh isKindOf "StaticWeapon") && {!alive driver _veh}) then {_ai assignAsDriver _veh; [_ai] orderGetIn true};
			
			_Slow_speed = if(abs(speed _veh) < 15)then[{_Slow_speed+1},{0}];
			if (time > _time1) then {_time1 = time + 30; _Slow_speed = 0};
			
			if (_veh distance2D _tag <= _dist || {_Slow_speed > 12} || {_veh isKindOf "StaticWeapon"} || {surfaceIsWater _pos && {_veh isKindOf "LandVehicle"} && {surfaceIsWater ([_veh, 15, getDir _veh] call BIS_fnc_relPos)}} || {_veh isKindOf "Ship" && {!(surfaceIsWater ([_veh, 60, getDir _veh] call BIS_fnc_relPos))}}) then {
				_crew = crew _veh;
				_driver = driver _veh;
				if !(_veh isKindOf "StaticWeapon") then {
					if!(_veh isKindOf "Ship")then[{doGetOut _ai},{_driver disableAI "MOVE"}];
					waitUntil {abs(speed _veh) < 5 && {!(_veh isKindOf "Helicopter") || {(getPos _veh select 2) < .2}}};
					_veh setVelocity [0,0,0];
					_veh engineOn false;
				};
				_ai leaveVehicle _veh; //
				FAR_remote_EH = [_ai, nil, "outveh", nil];
				publicVariable "FAR_remote_EH";
				_ai call FAR_out_veh;
				if (_driver == _ai) then [{_driver enableAI "MOVE"},{if(!isPlayer _driver)then{_driver call FAR_out_veh}}];
				_veh setVelocity [0,0,0];
				_veh engineOn false;
				_dist2 = _ai distance _tag;
				_previousPos = if(surfaceIsWater getPosASL _ai)then[{getPosASL _ai},{getPosATL _ai}]; //
			};
		},{
			if (vehicle _tag != _tag && {_ai distance _tag <= 10}) then {
				FAR_remote_EH = [_tag, nil, "outveh", nil];
				publicVariable "FAR_remote_EH";
				_tag call FAR_out_veh;
				_ai setPosASL (getPosASL _tag); //防载具阻挡
			};
			
			if (_ai distance _tag == _dist3 && {alive _ai} && {lifeState _ai != "INCAPACITATED"} && {_ai getVariable ["FAR_once_eh", true]} && {!(animationState _ai in ["unconscious","unconsciousoutprone"])}) then {
				if (_ai distance2D _tag > 5) then [{
					if (!(_ai getVariable ["FAR_AI_AUTOTARGET", true]) || {isNull (_ai findNearestEnemy _ai)} || {[_ai, "VIEW", (_ai findNearestEnemy _ai)] checkVisibility [eyePos _ai, eyePos (_ai findNearestEnemy _ai)] == 0}) then {
						_newPos = _tag getPos [(_ai distance2D _tag) - 4, _tag getDir _ai]; //3
						_newPos2 = [_newPos select 0, _newPos select 1, getPosASL _ai select 2];
						_ai setDir (_ai getDir _tag);
						_ai setPosASL _newPos2;
						[_ai,_newPos] spawn {
							params ["_ai","_newPos"];
							sleep .8;
							if (getPos _ai select 2 > .2) then {_ai setVelocity [0,0,0]; _ai setPos _newPos};
						};
						/*if (time > _time3) then {
							_ai doMove _pos;
							_ai moveTo _pos;
							_time3 = time + 15; //
						};*/
						_ai allowFleeing 0;
						_ai disableAI "MOVE"; //防止来回跑
					};
				},{
					if (_ai distance _tag > 5) then {_ai setPosASL (getPosASL _tag)};
				}];
			}; //ai强制移动
			
			if (_ai distance _tag < 43 && {_tag getVariable ["FAR_CallAI_Smoke", false] || {(_tag call FAR_enemy_visible || {_ai call FAR_enemy_visible}) && {abs((getPosATL _ai select 2)-(getPosATL _tag select 2)) < 2.5} && {_ai getVariable ["FAR_Throw_Smoke", 0] < _Throw} && {random 100 < FAR_ThrowSmokeProbability}}}) then {
				_smoke = [];
				{ if((_x select 0) in magazines _ai)then{_smoke pushback (_x select 1)} } forEach [["SmokeShell","SmokeShellMuzzle"],["SmokeShellBlue","SmokeShellBlueMuzzle"],["SmokeShellYellow","SmokeShellYellowMuzzle"],["SmokeShellGreen","SmokeShellGreenMuzzle"],["SmokeShellPurple","SmokeShellPurpleMuzzle"],["SmokeShellOrange","SmokeShellOrangeMuzzle"],["SmokeShellRed","SmokeShellRedMuzzle"]];
				if (count _smoke == 0) exitWith {};
				_ai stop true;
				//_ai disableAI "MOVE";
				_ai setDir (_ai getDir _tag);
				_v0Max = 19;
				_v0Max = _v0Max - (getFatigue _ai) * _fatEff * _v0Max;
				_ehATL = (ASLtoATL (eyePos _ai)) select 2;
				if (_ehATL < 1.4) then {_v0Max = _v0Max * (if(_ehATL < .8)then[{_GV0MaxP},{_GV0MaxC}])};
				_range = _tag distance2D _ai; //
				_a = if(_range > 7)then[{7.81},{if(_range > 1.2)then[{_range},{0}]}];
				_v0 = sqrt(_range * _a / sin (2 * _throwTheta)); //9.81
				if (_v0 > _v0Max) then {_v0 = _v0Max};
				_v0x = cos _throwTheta * _v0;
				_v0z = sin _throwTheta * _v0;
				_throwDir = _ai getDir _tag;
				_flyDirSin = sin _throwDir;
				_flyDirCos = cos _throwDir;
				_ai setVariable ["FAR_throwVel", [_flyDirSin * _v0x,_flyDirCos * _v0x,_v0z]];
				_SFEH = _ai addEventHandler ["fired", {
					_ai = _this select 0;
					_throwVel = _ai getVariable ["FAR_throwVel", [0,0,0]];
					if (_this select 1 == "THROW") then {(_this select 6) setVelocity _throwVel};
					_ai setVariable ["FAR_Throw_SFEH", 1];
				}];
				[_ai,_SFEH] spawn {
					params ["_ai", "_idx"];
					_time = time + 5;
					waitUntil {!isNil {_ai getVariable "FAR_Throw_SFEH"} || {time > _time}};
					_ai removeEventHandler ["fired", _idx];
					_ai stop false;
					//_ai enableAI "MOVE";
					sleep .1;
					_ai setVariable ["FAR_Throw_SFEH", nil];
				};
				_SSM = _smoke select 0;
				_tag setVariable ["FAR_CallAI_Smoke", nil];
				_ai setVariable ["FAR_Throw_Smoke", (_ai getVariable ["FAR_Throw_Smoke", 0]) + 1];
				sleep .2;
				_ai setDir (_ai getDir _tag);
				_ai forceWeaponFire [_SSM,_SSM];
				_ai stop false;
				//_ai enableAI "MOVE";
			};
		}];
		
		_Kit = false;
		if (FAR_ReviveMode in [2,3]) then [{
			switch FAR_ReviveMode do {
				case 2: { if ("Medikit" in items _ai || {"Medikit" in items _tag}) then [{_Stabi = false},{if ("FirstAidKit" in items _ai || {"FirstAidKit" in items _tag}) then [{_Stabi = true},{_Kit = true}];}]; };
				case 3: { if ("FirstAidKit" in items _ai || {"FirstAidKit" in items _tag} || {"Medikit" in items _ai} || {"Medikit" in items _tag}) then [{_Stabi = false},{_Stabi = true}]; };
			};
		},{
			if (_Stabi && {FAR_ReviveMode != 0}) then {_Stabi = false};
		}];
		
		_check = ( !alive _ai || {!(_ai getVariable ["FAR_once_eh", true])} || {lifeState _ai == "INCAPACITATED"} || {!alive _tag} || {_tag getVariable ["FAR_isUnconscious", 0] == 0} || {if(_Stabi)then[{_tag getVariable ["FAR_isStabilized",false]},{false}]} || {time > _moveTimeout} || {time > _moveTimeout2 && {_ai distance _tag > _callAI_dist}} || {abs(speed _tag) > 15} || {_tag getVariable ["FAR_CallAI_X", false]} || {_side != side _ai && {!(side _ai in FAR_SIDE_Medic)} && {!(_ai getVariable ["FAR_SIDE_Medic", false])}} || {captive _ai} || {_Kit} || {isPlayer _ai} || {!(simulationEnabled _ai)} || {[_ai,_tag] call FAR_callAI_checkCond} ); //
		
		if (surfaceIsWater getPosASL _tag && {_ai distance2D _tag <= 5} && {isNull objectParent _ai} && {isNull objectParent _tag}) exitWith {true};
		
		if (_ai distance _tag <= 5 && {isNull objectParent _ai} && {isNull objectParent _tag}) exitWith {true};
		
		_check
	};
	if (_check || {!(_tag getVariable ["FAR_act_menu",true])} || {_tag getVariable ["FAR_isDragged",false]} || {_tag getVariable ["FAR_isCarry",false]}) exitWith {if(isPlayer _tag)then{[_tag, _ai] remoteExec ["FAR_CallAiText2", _tag]}; call FAR_closeFN}; ////
	
	_dirVector = vectorDir _ai; 
    _upVector = vectorUp _ai;
	_ai setDir 270;
	_ai attachTo [_tag, [.85, .2, .01]];
	_ai setDir 270;
	//_ai disableAI "MOVE";
	//_ai setDir ([_ai, _tag] call BIS_fnc_dirTo);
	//_ai disableAI "ANIM"; //禁止AI改变动作的能力
	if(_Stabi)then[{[_ai,_tag,_side] call (if(FAR_actMode == 0)then[{FAR_Stabilize_AI},{FAR_Stabilize2_AI}])},{[_ai,_tag,_side] call (if(FAR_actMode == 0)then[{FAR_Revive_AI},{FAR_Revive2_AI}])}];
	detach _ai;
	_ai setVectorDirAndUp [_dirVector,_upVector];
	call FAR_closeFN;
};

FAR_IsFriendlyMedic_AI = {
	private ["_ai", "_tag", "_side"];
	_ai = _this select 0;
	_tag = _this select 1;
	_side = _this select 2;
	if ( alive _ai && {!isPlayer _ai} && {_side == side _ai || {side _ai in FAR_SIDE_Medic} || {_ai getVariable ["FAR_SIDE_Medic", false]}} && {!captive _ai} && {_ai in (call k1_allUnits)} && {_ai getVariable ["FAR_isUnconscious", 0] == 0} && {lifeState _ai != "INCAPACITATED"} && {!(_ai getVariable ["FAR_CallAiRevive", false])} && {FAR_ReviveMode in [1,3,4] || {"FirstAidKit" in items _ai} || {"FirstAidKit" in items _tag} || {"Medikit" in items _ai} || {"Medikit" in items _tag} || {FAR_ReviveMode == 0 && {(getNumber (configfile >> "CfgVehicles" >> typeOf _ai >> "attendant")) == 1}}} && {simulationEnabled _ai} && {!(["UAV_AI", typeOf _ai] call BIS_fnc_inString)} ) exitWith {true};
	false
}; //[_ai,true] call BIS_fnc_objectSide

FAR_callFriendlies_AI = {
	_tag = _this select 0;
	_ai = _tag getVariable ["FAR_call_AI", objNull];
	if (!isNull _ai) exitWith {if(isPlayer _tag && {!isPlayer _ai})then{[format["<t size = '.8'>医护兵 %1(AI): 我已经在路上<br/>按X键取消</t>", if(alive _ai)then[{name _ai},{"???"}]],-1,0,4,0,0,7374] spawn BIS_fnc_dynamicText}};
	private ["_ai", "_units", "_medics", "_side"];
	if (!FAR_water_rs && {getPosASL _tag select 2 < -.4}) exitWith {};
	_units = nearestObjects [_tag, ["CaManBase", "LandVehicle", "Helicopter", "Ship"], FAR_callAI_dist] - [_tag];
	
	{if(_x isKindOf "StaticWeapon" && {_x distance _tag > 100})then{_units=_units-[_x]}} forEach _units;//

	_medics = [];
	_side = _this select 1;
	{
		if (_x isKindOf "CaManBase") then [{
			if ([_x, _tag, _side] call FAR_IsFriendlyMedic_AI) then {_medics pushback _x};
		},{
			if (alive _x && {count crew _x > 0} && {!unitIsUAV _x}) then { ////
				{
					if ([_x, _tag, _side] call FAR_IsFriendlyMedic_AI) then {_medics pushback _x};
				} forEach crew _x;
			};
		}];
	} forEach _units;
	
	if (count _medics > 0) then {
		if (FAR_ReviveMode in [0,2,3]) then [{
			_medics1 = [];
			{
				_return = switch FAR_ReviveMode do {
					case 0: {(getNumber (configfile >> "CfgVehicles" >> typeOf _x >> "attendant")) == 1};
					case 2: {"Medikit" in items _x || {"Medikit" in items _tag}};
					case 3: {"FirstAidKit" in items _x || {"FirstAidKit" in items _tag} || {"Medikit" in items _x} || {"Medikit" in items _tag}};
					default {false};
				};
				if (_return) then {_medics1 pushback _x};
			} forEach _medics;

			if (count _medics1 > 0) then [{ //可治疗
				_ai = [_medics1, FAR_callAI_dist] call FAR_min_dist;
				if (!isNull _ai) then {[_ai, _tag, _side, false] remoteExec ["FAR_doMove_Revive", _ai]};
			},{
				if (_tag getVariable ["FAR_isStabilized",false] || {FAR_BleedOut <= 0}) exitWith {};
				_medics2 = _medics - _medics1; //可止血
				if (count _medics2 > 0) then {
					_ai = [_medics2, FAR_callAI_dist] call FAR_min_dist;
					if (!isNull _ai) then {[_ai, _tag, _side, true] remoteExec ["FAR_doMove_Revive", _ai]};
				};
			}];
		},{
			_ai = [_medics, FAR_callAI_dist] call FAR_min_dist;
			if (!isNull _ai) then {[_ai, _tag, _side, false] remoteExec ["FAR_doMove_Revive", _ai]};
		}];
	};
};


